Application.MailMergeBeforeMerge event (Word)
Occurs when a merge is executed before any records merge.
Syntax
expression.MailMergeBeforeMerge (Doc, StartRecord, EndRecord, Cancel)
expression A variable that represents an Application object.
For information about using events with the Application object, see Using events with the 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 | True stops the mail merge process before it starts. |
Example
This example displays a message before the mail merge process begins, asking the user if they want to continue. If the user clicks No, the merge process is canceled. This example assumes that you have declared an application variable called MailMergeApp in your general declarations and have set the variable equal to the Microsoft Word Application object.
Private Sub MailMergeApp_MailMergeBeforeMerge(ByVal Doc As Document, _
ByVal StartRecord As Long, ByVal EndRecord As Long, _
Cancel As Boolean)
Dim intVBAnswer As Integer
'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, "MailMergeBeforeMerge Event")
'If users response to question is No, cancel the 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
See also
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.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기