WPS 基础接口 > 文字 API 参考 > Application > 事件 > Application.MailMergeBeforeRecordMerge 事件
在针对合并中的单个记录执行合并时发生。

语法

表达式.Private Sub object_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)

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

参数

名称 必选/可选 数据类型 说明
Doc 必选 Document 邮件合并主文档。
Cancel 必选 Boolean 如果该参数值为 True,则仅在当前记录的邮件合并过程开始前停止该过程。

示例

以下示例验证邮政编码(在该示例中是第 6 个字段)的长度是否小于五位数字,以及是否仅取消该记录的合并。该示例假定在一般声明中声明了一个名为 MailMergeApp 的应用程序变量,并将 WPS Application 对象赋给该变量。

示例代码
function Application_MailMergeBeforeRecordMerge(Doc,Cancel) {

    let intZipLength

    intZipLength = ActiveDocument.MailMerge.DataSource.DataFields.Item(6).Value.length
    //Cancel merge of this record only if
    //the ZIP Code is fewer than five digits
    if(intZipLength < 5) {
        Cancel.Value = true
    }
}


请参阅