Field Object (Publisher)

Represents a field. The Field object is a member of the Fields collection. The Fields collection represents the fields in a selection, range, or publication.

The pbFieldPageNumber constant is a member of the PbFieldType group of constants, which includes all the various field types.

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 publication. The following counts the number of fields in the active publication and displays the count in a message.

Sub CountFields() 
 Dim pagPage As Page 
 Dim shpShape As Shape 
 Dim fldField As Field 
 Dim intFields As Integer 
 Dim intCount As Integer 
 
 For Each pagPage In ActiveDocument.Pages 
 For Each shpShape In pagPage.Shapes 
 If shpShape.Type = pbTextFrame Then 
 intCount = intCount + shpShape.TextFrame.TextRange.Fields.Count 
 End If 
 Next 
 Next 
 If intCount > 0 Then 
 MsgBox "You have " & intCount & " fields in your publication." 
 Else 
 MsgBox "You have no fields in your publication." 
 End If 
End Sub
Show:
© 2014 Microsoft