Application.MailMergeBeforeMerge 事件 (Word)

在合并任何记录之前于执行合并时发生。

语法

表达式MailMergeBeforeMerge (DocStartRecordEndRecordCancel)

expression:表示 Application 对象的变量。

有关对 Application 对象使用事件的信息,请参阅 将事件与 Application 对象配合使用

参数

名称 必需/可选 数据类型 说明
Doc 必需 Document 邮件合并主文档。
StartRecord 必需 Long 要包含在邮件合并中的数据源的第一个记录。
EndRecord 必需 Long 要包含在邮件合并中的数据源的最后一个记录。
Cancel 必需 Boolean 真正 开始前停止邮件合并过程。

示例

以下示例在邮件合并过程开始前显示一条消息,询问用户是否继续。 如果用户单击"否",则取消邮件合并过程。 该示例假定在一般声明中声明了一个名为 MailMergeApp 的应用程序变量,并将 Microsoft Word Application 对象赋给该变量。

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

另请参阅

Application 对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。