Fields.Add method (Word)

Adds a Field object to the Fields collection. Returns the Field object at the specified range.

Syntax

expression.Add (Range, Type, Text, PreserveFormatting)

expression Required. A variable that represents a 'Fields' collection.

Parameters

Name Required/Optional Data type Description
Range Required Range object The range where you want to add the field. If the range isn't collapsed, the field replaces the range.
Type Optional Variant Can be any WdFieldType constant. For a list of valid constants, consult the Object Browser. The default value is wdFieldEmpty.
Text Optional Variant Additional text needed for the field. For example, if you want to specify a switch for the field, you would add it here.
PreserveFormatting Optional Variant True to have the formatting that's applied to the field preserved during updates.

Return value

Field

Remarks

You cannot insert some fields (such as wdFieldOCX and wdFieldFormCheckBox) by using the Add method of the Fields collection. Instead, you must use specific methods such as the AddOLEControl method and the Add method for the FormFields collection.

Example

This example inserts a USERNAME field at the beginning of the selection.

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

This example inserts a LISTNUM field at the end of the selection. The starting switch is set to begin at 3.

Selection.Collapse Direction:=wdCollapseEnd 
ActiveDocument.Fields.Add Range:=Selection.Range, _ 
 Type:=wdFieldListNum, Text:="\s 3"

This 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

See also

Fields Collection Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.