Publisher) (EmailMergeEnvelope 物件
代表電子郵件容器 (信封) ,該信封) 保存合併到電子郵件合併的 Microsoft Publisher 檔。
註解
EmailMergeEnvelope物件的屬性會對應至 [檔案] 功能表上 [發行者] 使用者介面 (中 [合併至Email] 對話方塊中必要和選擇性設定的組合,指向 [傳送Email],選擇 [傳送Email合併],然後選擇 [選項) ]。
您必須先指定EmailMergeEnvelope物件之To屬性的值,或 Publisher 傳回錯誤,才能使用MailMerge物件的Execute方法傳送合併的電子郵件。
範例
下列 Microsoft Visual Basic for Applications (VBA) 宏會示範如何指派代表電子郵件合併之 EmailMergeEnvelope 物件的某些屬性,然後傳送產生的電子郵件訊息、邀請。 宏會連接到資料來源、將值指派給EmailMergeEnvelope物件的To和Subject屬性,並將包含合併欄位和一些額外文字的文字方塊新增至電子郵件訊息。 然後,它會使用MailMerge物件的Execute方法來執行合併並傳送電子郵件。
此範例中參考的資料來源是簡單的索引標籤分隔文字檔,其中分別包含標題為First、Last和Email Address的三個數據行。
執行程式碼之前,請先建立文字檔,在其中新增一個或多個資料列,將檔案命名為 DataSource.txt 並儲存到磁碟。 將 PathToFile 變數取代為您的路徑,以將檔案的路徑新增至程式碼。
如果您執行本範例中的程式碼一次以上,就會發生錯誤,因為 Publisher 會在您每次執行程式碼時連接至資料來源,而導致出版物連接至多重資料來源。 有多重資料來源的連接存在時,Publisher 會在主版 (合併後) 合併列印資料來源中新增一欄,以指定每一筆記錄的特定資料來源。 因此,Publisher 等於是變更了所有資料來源欄的索引編號,而導致此程式碼中所使用的索引 (例如,MailMergeField1) 不正確。
Public Sub EmailMergeEnvelope_Example()
Dim pubShape As Publisher.Shape
Dim pubMailMerge As Publisher.MailMerge
'Connect to the data source.
Set pubMailMerge = ThisDocument.MailMerge
pubMailMerge.OpenDataSource "PathToFile \DataSource.txt"
'Assign "Email Address" to the To field of the email message.
pubMailMerge.EmailMergeEnvelope.To = pubMailMerge.DataSource.DataFields.Item(3)
'Add text to the Subject field of the email message.
pubMailMerge.EmailMergeEnvelope.Subject = "Invitation"
'Insert two merge fields and some additional text in a text box in the body of the message.
Set pubShape = ThisDocument.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 100, 100, 200, 100)
pubShape.TextFrame.TextRange.Text = "Dear "
pubShape.TextFrame.TextRange.InsertMailMergeField 1
pubShape.TextFrame.TextRange.InsertAfter " "
pubShape.TextFrame.TextRange.InsertMailMergeField 2
pubShape.TextFrame.TextRange.InsertAfter ": "
pubShape.TextFrame.TextRange.InsertAfter "You are invited!"
'Perform the merge.
pubMailMerge.Execute True, pbSendEmail
'Display a reminder
MsgBox "If your email client is not already open, remember to open it and send the email messages that are in the outbox."
End Sub
屬性
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。