共用方式為


Application.MailMergeBeforeMerge 事件 (Word)

會在任何記錄合併之前執行合併時發生。

語法

表情MailMergeBeforeMerge (文件StartRecordEndRecord取消)

expression 代表 Application 物件的變數。

關於如何與 應用程式 物件使用事件的資訊,請參見 使用事件搭配應用程式物件

參數

名稱 必要/選用 資料類型 描述
Doc 必要 Document 合併列印主文件。
起始紀錄 必要 Long 資料來源中要包含在合併列印中的第一筆記錄。
結束紀錄 必要 Long 資料來源中要包含在合併列印中的最後一筆記錄。
Cancel 必要 Boolean True 是表示 合併列印程序開始前才停止。

範例

這個範例會在合併列印程序開始之前顯示訊息,詢問使用者是否要繼續。 如果使用者按一下 [否],就會取消合併程序。 這個範例會假設您已經在一般宣告中宣告了名稱為 MailMergeApp 的應用程式變數,並且已將該變數設定為與 Microsoft Word Application 物件相同。

Private Sub MailMergeApp_MailMergeBeforeMerge(ByVal Doc As Document, _ 
 ByVal StartRecord As Long, ByVal EndRecord As Long, _ 
 Cancel As Boolean) 
 
 Dim intVBAnswer As Integer 
 
 '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, "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 = vbNo Then 
 Cancel = True 
 MsgBox "You have canceled mail merge for " & _ 
 Doc.Name & "." 
 End If 
 
End Sub

另請參閱

Application 物件

支援和意見反應

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