将电子邮件正文复制到现有的excel文档/每个单元格的电子邮件正文

时间:2019-09-10 14:22:20

标签: excel vba outlook

我每天收到相同的电子邮件,相同的主题和相同的发件人。我要完成的工作只是抓住电子邮件的某些内容,别无其他,还按单元将其分解并排除标题。

我试图在线收集一些代码以使我入门,但似乎我对VBA还是一无所知,如果这不起作用,我可能只是使用Python创建了一个自动处理程序来完成此操作,但尝试避免这种情况因为我不会是唯一使用它的人。非常感谢您为我指明正确的方向。

我尝试了以下操作,但收到错误消息(运行时错误'5':无效的过程调用或参数),我无法弄清楚。

Example of E-Mail

Sub GetFromOutlook()

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(“impMail”)

i = 1

For Each OutlookMail In Folder.Items
'If OutlookMail.ReceivedTime >= Range(“email_Receipt_Date”).Value Then
If OutlookMail.ReceivedTime >= Range(“start_Date”).Value And OutlookMail.ReceivedTime <= Range(“end_Date”) And OutlookMail.Sender = Range(“sender”) Then
'If OutlookMail.ReceivedTime >= Range(“start_Date”).Value And OutlookMail.ReceivedTime <= Range(“end_Date”) And OutlookMail.Subject = Range(“Subject”) Then
'If OutlookMail.ReceivedTime >= Range(“email_Receipt_Date”).Value And Date <= 28 – mar – 2018 Then
'Range(“email_Subject”).Offset(i, 0).Value = OutlookMail.Subject
'Range(“email_Subject”).Offset(i, 0).Columns.AutoFit
'Range(“email_Subject”).Offset(i, 0).VerticalAlignment = xlTop
'Range(“email_Date”).Offset(i, 0).Value = OutlookMail.ReceivedTime
'Range(“email_Date”).Offset(i, 0).Columns.AutoFit
'Range(“email_Date”).Offset(i, 0).VerticalAlignment = xlTop
'Range(“email_Sender”).Offset(i, 0).Value = OutlookMail.SenderName
'Range(“email_Sender”).Offset(i, 0).Columns.AutoFit
'Range(“email_Sender”).Offset(i, 0).VerticalAlignment = xlTop
Range(“email_Body”).Offset(i, 0).Value = OutlookMail.Body
Range(“email_Body”).Offset(i, 0).Columns.AutoFit
Range(“email_Body”).Offset(i, 0).VerticalAlignment = xlTop

i = i + 1
End If
Next OutlookMail

Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

0 个答案:

没有答案