全部显示

MailMergeBeforeMerge 事件

       

执行合并后,在合并任何记录之前,该事件发生。

Private Sub object_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)

object  在类模块事件中声明的 Application 类型对象。有关使用 Application 对象事件的详细信息,请参阅使用 Application 对象事件

Doc  邮件合并主文档。

StartRecord   要包含在邮件合并中的数据源中的第一条记录。

EndRecord   要包含在邮件合并中的数据源中的最后一条记录。

Cancel   若该参数值为 True,则在邮件合并开始前停止该过程。

示例

该示例在邮件合并过程开始前显示一条消息,询问用户是否继续。如果用户单击“否”,则取消邮件合并过程。该示例假定在一般声明中声明了一个名为 MailMergeApp 的应用程序变量,并将 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 cancelled
    If intVBAnswer = vbNo Then
        Cancel = True
        MsgBox "You have cancelled mail merge for " & _
            Doc.Name & "."
    End If

End Sub