我有一個包含表格的word文檔,它是電子郵件的日誌。第1列是電子郵件的日期,第2列是主題行,第3列中我想嵌入實際的電子郵件,因此它顯示爲MSG文件。 這個VBA是在word文檔中,我用word打開了vba中的郵件項目。如何將mailitem作爲msg文件嵌入word文檔
如何嵌入郵件?
Sub create_log()
Dim appOL As Outlook.Application
Dim appFolder As Outlook.Folder
Dim nsOL As Outlook.NameSpace
Dim mailItem As Outlook.mailItem
Dim items As Outlook.items
Set appOL = New Outlook.Application
Set nsOL = appOL.GetNamespace("MAPI")
Set appFolder = Session.GetDefaultFolder(olFolderInbox).Folders("Email_log")
Dim doc As Word.Document
Dim tbl As Word.Table
Dim cell As Word.cell
Dim row As Long
Dim rows_needed As Long
Set doc = Application.ActiveDocument
If doc.Tables.Count > 1 Then
MsgBox "Too many tables, there should only be one"
Exit Sub
End If
Set tbl = doc.Tables(1)
rows_needed = appFolder.items.Count - tbl.Rows.Count
While rows_needed > 0
tbl.Rows.Add
rows_needed = rows_needed - 1
Wend
Set items = appFolder.items
items.Sort "ReceivedTime", False
row = 2
For Each mailItem In items
tbl.cell(row, 1).Range.Text = Left(mailItem.ReceivedTime, 12)
tbl.cell(row, 2).Range.Text = mailItem.Subject
tbl.cell(row, 3).Range. ***how do I add mailItem***
row = row + 1
Next mailItem
End Sub
這就是我想要的最終結果。請注意文檔和表格已經存在,宏只填寫表格中的單元格。
你可以添加一個圖像的例子,你的word文檔應該看起來像什麼? – 0m3r