Application.MailMergeBeforeMerge event (Publisher)

Occurs when a merge is executed before any records in a mail merge have merged.

Syntax

expression.MailMergeBeforeMerge (Doc, StartRecord, EndRecord, Cancel)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Doc Required Document The mail merge main document.
StartRecord Required Long The first record in the data source to include in the mail merge.
EndRecord Required Long The last record in the data source to include in the mail merge.
Cancel Required Boolean Stops the mail merge process before it starts.

Remarks

To access the Application object events, declare an Application object variable in the General Declarations section of a code module, and then set the variable equal to the Application object for which you want to access events.

For information about using events with the Microsoft Publisher Application object, see Using events with the Application object.

Example

This example displays a message before the mail merge process begins, asking the user if they want to continue. If the user chooses No, the merge process is canceled.

Private Sub MailMergeApp_MailMergeBeforeMerge(ByVal Doc As Document, _ 
 ByVal StartRecord As Long, ByVal EndRecord As Long, _ 
 Cancel As Boolean) 
 
 Dim intVBAnswer As Integer 
 
 Set Doc = ActiveDocument 
 
 'Request whether the user wants to continue with the merge 
 intVBAnswer = MsgBox("Mail Merge for " & Doc.Name & _ 
 " is now starting. Do you want to continue?", _ 
 vbYesNo, "Event!") 
 
 'If user's response to question is No, then cancel merge process 
 'and deliver a message to the user stating the merge is canceled 
 If intVBAnswer = vbNo Then 
 Cancel = True 
 MsgBox "You have canceled mail merge for " & _ 
 Doc.Name & "." 
 End If 
 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.