共用方式為


Application.MailMergeBeforeMerge 事件 (Publisher)

此事件發生於執行合併時,在合併列印中任何記錄被合併之前。

語法

運算式MailMergeBeforeMerge (DocStartRecordEndRecordCancel)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Doc 必要 Document 合併列印主文件。
StartRecord 必要 Long 資料來源中要包含在合併列印中的第一筆記錄。
EndRecord 必要 Long 資料來源中要包含在合併列印中的最後一筆記錄。
Cancel 必要 Boolean 會在合併列印程序開始之前停止該程序。

註解

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

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

範例

這個範例會在合併列印程序開始之前顯示訊息,詢問使用者是否要繼續。 如果使用者選擇 [否],則會取消合併程式。

Private Sub MailMergeApp_MailMergeBeforeMerge(ByVal Doc As Document, _ 
 ByVal StartRecord As Long, ByVal EndRecord As Long, _ 
 Cancel As Boolean) 
 
 Dim intVBAnswer As Integer 
 
 Set Doc = ActiveDocument 
 
 '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, "Event!") 
 
 'If user's response to question is No, then cancel merge process 
 'and deliver a message to the user stating the merge is canceled 
 If intVBAnswer = vbNo Then 
 Cancel = True 
 MsgBox "You have canceled mail merge for " & _ 
 Doc.Name & "." 
 End If 
 
End Sub

支援和意見反應

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