TextInput object (Word)
Represents a single text form field.
Use FormFields (Index), where Index is either the bookmark name associated with the text form field or the index number, to return a FormField object. Use the TextInput property with the FormField object to return a TextInput object. The following example deletes the contents of the text form field named "Text1" in the active document.
ActiveDocument.FormFields("Text1").TextInput.Clear
The index number represents the position of the form field in the FormFields collection. The following example checks the type of the first form field in the active document. If the form field is a text form field, the example sets "Mission Critical" as the value of the field.
If ActiveDocument.FormFields(1).Type = wdFieldFormTextInput Then
ActiveDocument.FormFields(1).Result = "Mission Critical"
End If
The following example determines whether the ffield variable represents a valid text form field in the active document before it sets the default text.
Set ffield = ActiveDocument.FormFields(1).TextInput
If ffield.Valid = True Then
ffield.Default = "Type your name here"
Else
MsgBox "First field is not a text box"
End If
Use the Add method with the FormFields object to add a text form field. The following example adds a text form field at the beginning of the active document and then sets the name of the form field to "FirstName."
Set ffield = ActiveDocument.FormFields.Add( _
Range:=ActiveDocument.Range(Start:=0, End:=0), _
Type:=wdFieldFormTextInput)
ffield.Name = "FirstName"
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.