Share via


Fields Object

Publisher Developer Reference

A collection of Field objects that represent all the fields in a text range.

Remarks

The Count property for this collection in a publication returns the number of items in a specified shape or selection.

Example

Use the Fields property to return the Fields collection. 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 example displays the field code and the result of the first field in each text box in the active publication.

Visual Basic for Applications
  Sub ShowFieldCodes()
    Dim pagPage As Page
    Dim shpShape As Shape
For Each pagPage In ActiveDocument.Pages
    For Each shpShape In pagPage.Shapes
        If shpShape.Type = pbTextFrame Then
            With shpShape.TextFrame.TextRange
                If .Fields.Count > 0 Then
                    MsgBox "Code =  " & .Fields(1).Code & vbLf _
                        & "Result =  " & .Fields(1).Result & vbLf
                End If
            End With
        End If
    Next
Next

End Sub

See Also