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