Field Object

Multiple objects
Field
Multiple objects

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

Using the Field Object

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

Use the Add method to add a field to the Fields collection. 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

The wdFieldDate constant is part of the WdFieldType group of constants, which includes all the various field types.

Properties | Application Property | Code Property | Creator Property | Data Property | Index Property | InlineShape Property | Kind Property | LinkFormat Property | Locked Property | Next Property | OLEFormat Property | Parent Property | Previous Property | Result Property | ShowCodes Property | Type Property

Methods | Copy Method | Cut Method | Delete Method | DoClick Method | Select Method | Unlink Method | Update Method | UpdateSource Method

Parent Objects | Field Object | InlineShape Object

Child Objects | Field Object | InlineShape Object | LinkFormat Object | OLEFormat Object | Range Object

See Also | MailMergeField Object