我希望将发件人和邮件正文粘贴到我的 Excel 文件中。
我已经达到了粘贴发件人的程度,但是当粘贴作为表格的正文时,它会破坏格式,因为它粘贴在一个单元格中。
如何将表格粘贴到发件人旁边的电子邮件中?
我认为粘贴表格的代码应该从注释开始:'在此处将表格粘贴到电子邮件正文中。
Private Sub CommandButton1_Click()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("ABV")
i = 2
With ThisWorkbook.Sheets("Sheet2")
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= .Range("C1") Then
With .Cells(i, 1)
.Value = OutlookMail.SenderName
.Columns.AutoFit
.VerticalAlignment = xlTop
End With
With .Cells(i, 2)
'Paste the table inside the email body here
End With
i = i + 1
End If
Next OutlookMail
End With
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
此文件夹中的所有电子邮件都将包含一个表格,因此我想在每个发件人及其表格被粘贴时循环。