WPS 基础接口 > 文字 API 参考 > Application > 事件 > Application.MailMergeBeforeMerge 事件
在合并任何记录之前于执行合并时发生。

语法

表达式.Private Sub object_MailMergeBeforeMerge(ByVal Doc As Document, ByVal StartRecord As Long, ByVal EndRecord As Long, Cancel As Boolean)

表达式   一个代表 Application 对象的变量,该对象已使用类模块?(类模块:包含新对象的定义的模块。当创建类的新实例时,即创建新对象。模块中定义的过程成为该对象的属性和方法。)中的事件声明。有关使用 Application 对象事件的详细信息,请参阅 使用 Application 对象事件。

参数

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

示例

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

示例代码
function Application_MailMergeBeforeMerge(Doc, StartRecord, EndRecord, Cancel) {
	
    let intVBAnswer

    //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?", jsYesNo, "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 == jsResultNo) {
        Cancel = true
        MsgBox("You have canceled mail merge for " + Doc.Name + ".")
    }
}


请参阅