Class MailMergeField (Word VBA)

The class MailMergeField represents a single mail merge field in a document. The MailMergeDataField object is a member of the MailMergeDataFields collection. The MailMergeDataFields collection includes all the mail merge related fields in a document.

The main procedures of class MailMergeField are Copy, Delete, Select, MailMergeFields.Add, MailMergeFields.AddAsk, MailMergeFields.AddFillIn, MailMergeFields.AddIf, MailMergeFields.AddMergeRec, MailMergeFields.AddMergeSeq, MailMergeFields.AddNext, MailMergeFields.AddNextIf, MailMergeFields.AddSet and MailMergeFields.AddSkipIf

Set

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

Dim mmf as MailMergeField
Set mmf = ActiveDocument.MailMerge.Fields(Index:=1)

The following procedures can be used to set variables of type MailMergeField: Next, Previous, MailMergeFields.Add, MailMergeFields.Item, MailMergeFields.AddAsk, MailMergeFields.AddFillIn, MailMergeFields.AddIf, MailMergeFields.AddMergeRec, MailMergeFields.AddMergeSeq, MailMergeFields.AddNext, MailMergeFields.AddNextIf, MailMergeFields.AddSet, MailMergeFields.AddSkipIf and MailMerge.Fields

Themes

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

Add with its procedures MailMergeFields.Add, MailMergeFields.AddAsk, MailMergeFields.AddFillIn, MailMergeFields.AddIf, MailMergeFields.AddMergeRec, MailMergeFields.AddMergeSeq, MailMergeFields.AddNext, MailMergeFields.AddNextIf, MailMergeFields.AddSet and MailMergeFields.AddSkipIf

Methods

These are the main methods of the MailMergeField class

Copy - Copies the specified mail merge field to the Clipboard.

ActiveDocument.MailMerge.Fields(1).Copy

Delete - Deletes the specified mail merge field.

ActiveDocument.MailMerge.Fields(1).Delete

Select - Selects the specified mail merge field.

ActiveDocument.MailMerge.Fields(1).Select

Properties

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

ActiveDocument.MailMerge.Fields(1).Code =

Locked true if the specified field is locked.

ActiveDocument.MailMerge.Fields(1).Locked = True

Next returns the next mail merge field in the collection of mail merge fields.

Dim mmfNext As MailMergeField
Set mmfNext = ActiveDocument.MailMerge.Fields(1).Next

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

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

Previous returns the previous mail merge field in the collection of mail merge fields.

Dim mmfPrevious As MailMergeField
Set mmfPrevious = ActiveDocument.MailMerge.Fields(1).Previous

Type returns the field type.

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

MailMergeFields.Count returns a Long that represents the number of mail merge fields in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.MailMerge.Fields.Count

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

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