Class Field (Word VBA)

The class Field 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.

The main procedures of class Field are Copy, Delete, Select and Fields.Add


To use a Field class variable it first needs to be instantiated, for example

Dim fld as Field
Set fld = ActiveDocument.Fields(Index:=1)

The following procedures can be used to set variables of type Field: Next, Previous, Fields.Add, Fields.Item, Indexes.MarkEntry, InlineShape.Field, Selection.NextField, Selection.PreviousField, TablesOfAuthorities.MarkCitation, TablesOfContents.MarkEntry, TablesOfFigures.MarkEntry, Document.Fields, Range.Fields and Selection.Fields

For Each

Here is an example of processing the Field items in a collection.

Dim fld As Field
For Each fld In ActiveDocument.Fields
    	If fld.LinkFormat.AutoUpdate = False  Then fld.LinkFormat.Update
Next fld


The following procedures in this class have been grouped together and are described on a separate theme page

Format with its procedures LinkFormat and OLEFormat


These are the main methods of the Field class

Copy - Copies the specified field to the Clipboard.


Delete - Deletes the specified field.


Select - Selects the specified field.


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

Dim fld As Field
Set fld = ActiveDocument.Fields.Add(Range:=)


Code returns a Range object that represents a field's code.

ActiveDocument.Fields(1).Code =

Data returns or sets data in an ADDIN field.

ActiveDocument.Fields(1).Data =

Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveDocument.Fields(1).Index

InlineShape returns an InlineShape object that represents the picture, OLE object, or ActiveX control that is the result of an INCLUDEPICTURE or EMBED field.

Dim iseInlineShape As InlineShape
Set iseInlineShape = ActiveDocument.Fields(1).InlineShape

Kind returns the type of link for a Field object.

Dim wfkKind As WdFieldKind
wfkKind = ActiveDocument.Fields(1).Kind

Locked true if the specified field is locked.

ActiveDocument.Fields(1).Locked = True

Next returns the next object in the collection.

Dim fldNext As Field
Set fldNext = ActiveDocument.Fields(1).Next

Parent returns an object that represents the parent object of the specified Field object.

Dim objParent As Object
Set objParent = ActiveDocument.Fields(1).Parent

Previous returns the previous object in the collection.

Dim fldPrevious As Field
Set fldPrevious = ActiveDocument.Fields(1).Previous

Result returns a Range object that represents a field's result.

ActiveDocument.Fields(1).Result =

ShowCodes true if field codes are displayed for the specified field instead of field results.

ActiveDocument.Fields(1).ShowCodes = True

Type returns the field type.

Dim wftType As WdFieldType
wftType = ActiveDocument.Fields(1).Type

Fields.Count returns a Long that represents the number of fields in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Fields.Count

Fields.Locked true if all fields in the Fields collection are locked.

ActiveDocument.Fields.Locked =

Fields.Parent returns an object that represents the parent object of the specified Fields object.

Dim objParent As Object
Set objParent = ActiveDocument.Fields.Parent