共用方式為


Application.MailMergeBeforeRecordMerge 事件 (Publisher)

會在合併中執行個別記錄的合併時發生。

語法

運算式MailMergeBeforeRecordMerge (DocCancel)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Doc 必要 Document 合併列印主文件。
Cancel 必要 Boolean 只有在目前這筆記錄的合併列印程序開始前才停止該程序。

註解

若要存取 Application 物件事件,請在程式碼模組 的 [一 般宣告] 區段中宣告 Application 物件變數,然後將變數設定為等於您要存取事件的 Application 物件。

如需搭配 Microsoft Publisher Application 物件使用事件的相關資訊,請參閱 搭配 Application 物件使用事件

範例

本範例會確認 ZIP Code (的長度,在此範例中為欄位編號 6) 小於 5,如果是,則只會取消該記錄的合併。

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 has fewer than five digits 
 If intZipLength < 5 Then 
 Cancel = True 
 End If 
 
End Sub

若要發生此事件,必須將下一行程式碼放在模組的全域宣告區段中,並執行下列初始化程式。

Private WithEvents MailMergeApp As Application 
 
Sub InitializeMailMergeApp() 
 Set MailMergeApp = Publisher.Application 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應