全部显示

MailMergeBeforeRecordMerge 事件

       

在合并中执行单独记录的合并时,该事件发生。

Private Sub object_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)

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

Doc    邮件合并主文档。

Cancel   如果该参数值为 True,则仅在当前记录的邮件合并过程开始前停止该过程。

示例

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

Private Sub MailMergeApp_MailMergeBeforeRecordMerge(ByVal _
    Doc As Document, Cancel As Boolean)

        Dim intZipLength As Integer

        intZipLength = Len(ActiveDocument.MailMerge _
            .DataSource.DataFields(6).Value)

        'Cancel merge of this record only if
        'the zip code is less than five digits
        If intZipLength < 5 Then
            Cancel = True
        End If

End Sub