Suppress unwanted jumping/scrolling on Word 2013 VBA Script -


when accessing legacy form field values in word 2013 document (getting or setting):

' myfield = activedocument.formfields("myfield").result  ' set activedocument.formfields("myfield").result = myvalue 

the document weirdly jumps/scrolls down , , stops @ complete different position (it seems jump lines referred fields positioned).

have @ this screencast or a sample file error can viewed.

i have used

application.screenupdating = false 

at beginning of sub and

application.screenupdating = true 

at end of sub unfortunately doesn't help.

what have modify in order suppress behaviour?

i found clue solution on word mvp site. pointed out, issue when access properties of formfield object, focus set form field. can see behavior when browsing form fields through locals window in vba editor.

instead of using formfield object, access result property through bookmark object.

change this:

myfield = activedocument.formfields("myfield").result 

to this:

myfield = activedocument.bookmarks("myfield").range.fields(1).result 

now can access value of field without changing focus in document. set value on field, can use text property.

activedocument.bookmarks("myfield").range.fields(1).result.text = myvalue 

hope helps!! :-)


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -