MailMergeFieldName Object

Microsoft Word Visual Basic

MailMergeFieldName Object

         
Documents (Document) MailMerge
MailMergeDataSource
MailMergeFieldNames (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.

Using the MailMergeFieldName Object

Use FieldNames(index), where index is the index number, to return a single MailMergeFieldName object. The index number represents the position of the field in the mail merge data source. The following example retrieves the name of the last field in the data source attached to the active document.

alast = ActiveDocument.MailMerge.DataSource.FieldNames.Count
afirst = ActiveDocument.MailMerge.DataSource.FieldNames(alast).Name
MsgBox afirst

You cannot add fields to the MailMergeFieldNames collection. Field names in a data source are automatically included in the MailMergeFieldNames collection.