我有一个带有表格的word文档,它是电子邮件的日志。第1列是电子邮件的日期,第2列是主题行,第3列我想嵌入实际的电子邮件,因此它显示为MSG文件。 这个VBA在word文档中,我已经用vba打开了邮件项目。
如何嵌入邮件项目?
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