共用方式為


Application.MailMergeDataSourceLoad 事件 (Publisher)

會在載入合併列印的資料來源時發生。

語法

運算式MailMergeDataSourceLoad (Doc)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Doc 必要 Document 合併列印主文件。

註解

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

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

範例

這個範例會在開始載入資料來源時,顯示包含該資料來源檔案名稱的訊息。

Private Sub MailMergeApp_MailMergeDataSourceLoad(ByVal Doc As Document) 
 Dim strDSName As String 
 Dim intDSLength As Integer 
 Dim intDSStart As Integer 
 
 'Pull out of the Name property (which includes path and file name) 
 'only the file name using Visual Basic commands Len, InStrRev, and Right 
 intDSLength = Len(ActiveDocument.MailMerge.DataSource.Name) 
 intDSStart = InStrRev(ActiveDocument.MailMerge.DataSource.Name, "\") 
 intDSStart = intDSLength - intDSStart 
 strDSName = Right(ActiveDocument.MailMerge.DataSource.Name, intDSStart) 
 
 'Deliver a message to user when data source is loading 
 MsgBox "Your data source, " & strDSName & ", is now loading." 
End Sub

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

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

支援和意見反應

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