matejs
matejs

Reputation: 3536

How do i edit form field value in MS WORD 2007

How do i edit Text Form Field (legacy forms) in my document, so that i can then use new value of this field in my VBA script?

I have simple form with Text Form Field (Bookmark = TextFormField1). It is showing default text "default text".

I can access text of this field like this: ActiveDocument.FormFields("TextFormField1").Range.Text

However, if i change value of this field, it seems to delete the field itself, and replacing it with simple text - causing ActiveDocument.FormFields("TextFormField1").Range.Text to throw exception, because TextFormField1 does not exist anymore...

What am i doing wrong? How can i insert text in form field, and use this text in my VBA script?

Upvotes: 0

Views: 9219

Answers (2)

Try next code:

ThisDocument.FormFields("Index_Or_FormFieldName_or_Bookmarkname").TextInput.EditType Type:=wdRegularText, Default:="Your Form field text"  

But it rec the value in to the FormField very slowly.

Upvotes: 1

Olle Sjögren
Olle Sjögren

Reputation: 5384

Use the Result property:

ActiveDocument.FormFields("TextFormField1").Result = "Form field text"

Upvotes: 0

Related Questions