在电子邮件正文中插入Word.Document?

时间:2016-01-13 11:57:56

标签: excel vba email outlook

我正在尝试创建一个过程,将一个电子邮件正文(带有文本和表格)作为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 Sub

1 个答案:

答案 0 :(得分:0)

Word对象模型提供CopyPaste方法。有关详细信息,请参阅Chapter 17: Working with Item Bodies