Class TextInput (Word VBA)

The class TextInput represents a single text form field. To use a TextInput class variable it first needs to be instantiated, for example


Dim tit as TextInput
Set tit = ActiveDocument.FormFields(1).TextInput

Clear

Deletes the text from the specified text form field.


ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True 
If ActiveDocument.FormFields(1).Type = wdFieldFormTextInput Then 
 ActiveDocument.FormFields(1).TextInput.Clear 
End If

Default

Returns or sets the text that represents the default text box contents.


ActiveDocument.FormFields(1).TextInput.Default =

EditType

Sets options for the specified text form field.

EditType (Type, Default, Format, Enabled)


With ActiveDocument.FormFields.Add _ 
 (Range:=ActiveDocument.Range(0, 0), _ 
 Type:=wdFieldFormTextInput) 
 .Name = "Today" 
 .TextInput.EditType Type:=wdCurrentDateText, _ 
 Format:="M/d/yy", Enabled:=False 
End With

Arguments

The following argument is required

Type (WdTextFormFieldType) - The text box type.


Possible values are

wdCalculationText Calculation text field.
wdCurrentDateText Current date text field.
wdCurrentTimeText Current time text field.
wdDateText Date text field.
wdNumberText Number text field.
wdRegularText Regular text field.

Optional arguments

The following arguments are optional

Default (String) - The default text that appears in the text box.

Format (String) - The formatting string used to format the text, number, or date (for example, "0.00," "Title Case," or "M/d/yy"). For more examples of formats, see the list of formats for the specified text form field type in the Text Form Field Options dialog box.

Enabled (Boolean) - True to enable the form field for text entry.

Format

Returns the text formatting for the specified text box.


If ActiveDocument.FormFields(1).Type = wdFieldFormTextInput Then 
 MsgBox ActiveDocument.FormFields(1).TextInput.Format 
Else 
 MsgBox "First field is not a text form field" 
End If

Type

Returns the type of text form field. Possible return values are wdCalculationText - Calculation text field, wdCurrentDateText - Current date text field, wdCurrentTimeText - Current time text field, wdDateText - Date text field, wdNumberText - Number text field, wdRegularText - Regular text field.


Dim wtfType As WdTextFormFieldType
wtfType = ActiveDocument.FormFields(1).TextInput.Type

Valid

True if the specified form field object is a valid check box form field. Read-only Boolean.


If ActiveDocument.FormFields(1).TextInput.Valid = True Then 
 ActiveDocument.FormFields(1).Result = "Hello" 
End If

Width

Returns or sets the width, in points, of the specified text input field.


ActiveDocument.FormFields(1).TextInput.Width =