Word) (Application.MailMergeDataSourceLoad 事件

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

語法

運算式MailMergeDataSourceLoad (Doc)

表達 變數,表示已使用類別模組中的事件宣告的 'Application' 物件。 如需搭配 Application 物件使用 事件的相關資訊,請 參閱搭配 Application 物件使用事件

參數

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

範例

這個範例會在開始載入資料來源時,顯示包含該資料來源檔案名稱的訊息。 這個範例會假設您已經在一般宣告中宣告了名稱為 MailMergeApp 的應用程式變數,並且已將該變數設定為與 Word Application 物件相同。

Private Sub MailMergeApp_MailMergeDataSourceLoad(ByVal Doc As Document) 
 Dim strDSName As String 
 Dim intDSLength As Integer 
 Dim intDSStart As Integer 
 
 'Extract from the Name property only the file name 
 intDSLength = Len(Doc.MailMerge.DataSource.Name) 
 intDSStart = InStrRev(Doc.MailMerge.DataSource.Name, "\") 
 intDSStart = intDSLength - intDSStart 
 strDSName = Right(Doc.MailMerge.DataSource.Name, intDSStart) 
 
 'Deliver a message to user when data source is loading 
 MsgBox "Your data source, " & strDSName & ", is now loading." 
End Sub

另請參閱

Application 物件

支援和意見反應

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