Fields 对象(Word)Fields object (Word)

Field对象的集合,这些对象代表所选内容、范围或文档中的所有字段。A collection of Field objects that represent all the fields in a selection, range, or document.

备注Remarks

使用 字段 属性返回 字段 集合。Use the Fields property to return the Fields collection. 下面的示例更新选定内容中的所有域。The following example updates all the fields in the selection.

备注

[!注释] 使用 邮件合并 对象 字段 属性返回一个 MailMergeFields 集合。Use the Fields property with a MailMerge object to return a MailMergeFields collection.

Selection.Fields.Update

使用 添加 若要将字段添加到 字段 集合的方法。Use the Add method to add a field to the Fields collection. 下面的示例在所选内容的开头插入一个 DATE 域,然后显示结果。The following example inserts a DATE field at the beginning of the selection and then displays the result.

Selection.Collapse Direction:=wdCollapseStart 
Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _ 
 Type:=wdFieldDate) 
MsgBox myField.Result

使用字段(索引),其中索引是索引号,返回单个**Field** 对象。Use Fields (Index), where Index is the index number, to return a single Field object. 索引号代表选定内容、 范围或文档中的字段位置。The index number represents the position of the field in the selection, range, or document. 下面的示例显示活动文档中的域代码和结果的第一个字段。The following example displays the field code and the result of the first field in the active document.

If ActiveDocument.Fields.Count >= 1 Then 
 MsgBox "Code = " & ActiveDocument.Fields(1).Code & vbCr _ 
 & "Result = " & ActiveDocument.Fields(1).Result & vbCr 
End If

一个文档中,以上集合的 Count 属性返回正文部分的项目数。 要统计其他部分中的个数,请使用带有 Range 对象的集合。To count items in other stories use the collection with the Range object.

另请参阅See also

Word 对象模型参考Word Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.