多种对象![]() ![]() ![]() |
由 FormField 对象所组成的集合,该集合的元素代表了选定内容、区域或文档中的所有窗体域。
用 FormFields 属性可返回 FormFields 集合。下列示例统计活动文档中文本框窗体域的个数。
For Each aField In ActiveDocument.FormFields
If aField.Type = wdFieldFormTextInput Then count = count + 1
Next aField
MsgBox "There are " & count & " text boxes in this document"
用 FormFields 对象的 Add 方法可添加一个窗体域。下列示例在活动文档的开始处添加一个复选框并选中该复选框。
Set ffield = ActiveDocument.FormFields.Add( _
Range:=ActiveDocument.Range(Start:=0,End:=0), _
Type:=wdFieldFormCheckBox)
ffield.CheckBox.Value = True
用 FormFields (index) 可返回单个的 FormField 对象,其中 index 是书签名称或索引序号。下列示例将窗体域 Text1 的结果设置为“Don Funk”。
ActiveDocument.FormFields("Text1").Result = "Don Funk"
索引序号代表窗体域在选定内容、区域或文档中的位置。下列示例显示选定内容中第一个窗体域的名称。
If Selection.FormFields.Count >= 1 Then
MsgBox Selection.FormFields(1).Name
End If