Class MailMergeFieldName (Word VBA)

The class MailMergeFieldName represents a mail merge field name in a data source. The MailMergeFieldName object is a member of the MailMergeFieldNames collection. The MailMergeFieldNames collection includes all the data field names in a mail merge data source.

Set

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

Dim mmf as MailMergeFieldName
Set mmf = ActiveDocument.MailMerge.DataSource.FieldNames(Index:=1)

The following procedures can be used to set variables of type MailMergeFieldName: MailMergeFieldNames.Item and MailMergeDataSource.FieldNames

For Each

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

Dim mmfFieldName As MailMergeFieldName
For Each mmfFieldName In ActiveDocument.MailMerge.DataSource.FieldNames
	
Next mmfFieldName

Index

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

Dim lngIndex As Long
lngIndex = ActiveDocument.MailMerge.DataSource.FieldNames(1).Index

Name

Returns name of the specified object.

Dim strName As String
strName = ActiveDocument.MailMerge.DataSource.FieldNames(1).Name

Parent

Returns an object that represents the parent object of the specified MailMergeFieldName object.

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

MailMergeFieldNames.Count

Returns a Long that represents the number of mail merge field names in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.MailMerge.DataSource.FieldNames.Count

MailMergeFieldNames.Item

Returns an individual MailMergeFieldNames object in a collection.

Syntax : expression.Item (Index)

Index: The individual object to be returned.

Dim mmf As MailMergeFieldName
Set mmf = ActiveDocument.MailMerge.DataSource.FieldNames(Index:=1)

MailMergeFieldNames.Parent

Returns an object that represents the parent object of the specified MailMergeFieldNames object.

Dim objParent As Object
Set objParent = ActiveDocument.MailMerge.DataSource.FieldNames.Parent