在电子邮件正文中插入Word.Document?(Insert Word.Document in email body?)
我正在尝试创建一个过程,将一个电子邮件正文(带有文本和表格)作为Word.Document传递,然后通过电子邮件发送。 但是,我无法弄清楚如何将Word.Document插入电子邮件正文。
这就是我现在正在尝试的事情:
Sub CreateDraft(Destinatary As String, CC As String, Subject As String, Body As Word.Document) Dim OutApp As New Outlook.Application Dim OutMail As Outlook.MailItem Dim OutInspector As Outlook.Inspector Dim WordDoc As Word.Document Set OutMail = OutApp.CreateItem(olMailItem) With OutMail .To = Destinatary .CC = CC .Subject = Subject .Display Set OutInspector = OutMail.GetInspector Set WordDoc = OutInspector.WordEditor ' How do I insert the Body object to the email? Call .Save Call .Close(False) End With End Sub Sub SendButton_Click() Dim WordApp As New Word.Application Dim WordDoc As Word.Document Set WordDoc = WordApp.Documents.Add WordApp.Visible = False ThisWorkbook.Sheets(1).Range("A1:E10").Copy WordApp.Selection.PasteExcelTable False, False, False Call CreateDraft("abc@example.com", "", "Test", WordDoc) End SubI'm trying to create a procedure that is passed an email body (with text and tables) as a Word.Document and then sends it in an email. However I can't figure out how to insert the Word.Document to the email body.
This is what I'm trying now:
Sub CreateDraft(Destinatary As String, CC As String, Subject As String, Body As Word.Document) Dim OutApp As New Outlook.Application Dim OutMail As Outlook.MailItem Dim OutInspector As Outlook.Inspector Dim WordDoc As Word.Document Set OutMail = OutApp.CreateItem(olMailItem) With OutMail .To = Destinatary .CC = CC .Subject = Subject .Display Set OutInspector = OutMail.GetInspector Set WordDoc = OutInspector.WordEditor ' How do I insert the Body object to the email? Call .Save Call .Close(False) End With End Sub Sub SendButton_Click() Dim WordApp As New Word.Application Dim WordDoc As Word.Document Set WordDoc = WordApp.Documents.Add WordApp.Visible = False ThisWorkbook.Sheets(1).Range("A1:E10").Copy WordApp.Selection.PasteExcelTable False, False, False Call CreateDraft("abc@example.com", "", "Test", WordDoc) End Sub最满意答案
Word对象模型提供了复制和粘贴方法。 有关更多信息,请参见第17章:使用项目实体 。
The Word object model provides the Copy and Paste methods. See Chapter 17: Working with Item Bodies for more information.
更多推荐
发布评论