Class MailMerge (Word VBA)

The class MailMerge represents the mail merge functionality in Word.

The main procedures of class MailMerge are OpenDataSource and OpenHeaderSource


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

Dim mme as MailMerge
Set mme = ActiveDocument.MailMerge

MailMerge class variables can be set using the Document.MailMerge procedure.


Some procedures in this class have been grouped together in themes and are described on separate theme pages

Create with its procedures CreateDataSource and CreateHeaderSource
Email with its procedures MailAsAttachment and MailSubject
Display/Show with its procedures ShowSendToCustom and ShowWizard


These are the main methods of the MailMerge class

OpenDataSource - Attaches a data source to the specified document, which becomes a main document if it is not one already.

Dim strName As String: strName =  
ActiveDocument.MailMerge.OpenDataSource Name:=strName

OpenHeaderSource - Attaches a mail merge header source to the specified document.

Dim strName As String: strName =  
ActiveDocument.MailMerge.OpenHeaderSource Name:=strName


DataSource returns a MailMergeDataSource object that refers to the data source attached to a mail merge main document.

Dim mmdDataSource As MailMergeDataSource
Set mmdDataSource = ActiveDocument.MailMerge.DataSource

Destination returns or sets the destination of the mail merge results.

ActiveDocument.MailMerge.Destination = wdSendToEmail

Fields returns a read-only MailMergeFields collection that represents all the mail merge fields in the specified document.

Dim mmfsFields As MailMergeFields
Set mmfsFields = ActiveDocument.MailMerge.Fields

HighlightMergeFields true to highlight the merge fields in a document.

ActiveDocument.MailMerge.HighlightMergeFields = True

MailAddressFieldName returns or sets the name of the field that contains email addresses that are used when the mail merge destination is electronic mail.

ActiveDocument.MailMerge.MailAddressFieldName =

MailFormat returns a WdMailMergeMailFormat constant that represents the format to use when the mail merge destination is an email message.

ActiveDocument.MailMerge.MailFormat = wdMailFormatHTML

MainDocumentType returns or sets the mail merge main document type.

ActiveDocument.MailMerge.MainDocumentType = wdCatalog

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

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

State returns the current state of a mail merge operation.

Dim wmmState As WdMailMergeState
wmmState = ActiveDocument.MailMerge.State

SuppressBlankLines true if blank lines are suppressed when mail merge fields in a mail merge main document are empty.

ActiveDocument.MailMerge.SuppressBlankLines = True

ViewMailMergeFieldCodes true if merge field names are displayed in a mail merge main document. False if information from the current record is displayed.

ActiveDocument.MailMerge.ViewMailMergeFieldCodes =

WizardState returns or sets a Long indicating the current Mail Merge Wizard step for a document. The WizardState method returns a number that equates to the current Mail Merge Wizard step; a zero (0) means the Mail Merge Wizard is closed.

ActiveDocument.MailMerge.WizardState =