TextInput 对象

         
FormFields (FormField)
TextInput

该对象代表一个文本窗体域。

使用 TextInput 对象

可用 FormFields(index) 返回一个 FormFields 对象,其中 index 为该文本窗体域的书签名或索引号。可用 TextInput 属性及 FormField 对象返回一个 TextInput 对象。下例删除活动文档中“Text1”文本窗体域中的内容。

ActiveDocument.FormFields("Text1").TextInput.Clear

索引号表示该窗体域在 FormFields 集合中的位置。下例检查活动文档中第一个窗体域的类型。如果该窗体域为文本窗体域,本示例将该域值设为“Mission Critical”。

If ActiveDocument.FormFields(1).Type = wdFieldFormTextInput Then
    ActiveDocument.FormFields(1).Result = "Mission Critical"
End If

以下示例确定在 ffield 变量设置为默认的文本以前,是否在活动文档中代表一个有效的文本窗体域。

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

可用 Add 方法及 FormFields 对象添加一个文本窗体域。下例在活动文档开始处添加一文本窗体域,并将该域名设为“FirstName”。

Set ffield = ActiveDocument.FormFields.Add( _
    Range:=ActiveDocument.Range(Start:=0, End:=0), _
    Type:=wdFieldFormTextInput)
ffield.Name = "FirstName"