我想根据特定条件从Outlook中检索电子邮件。
在我的代码中,我指定了一个特定的文件夹。下面的示例中,文件夹名称是"PRE Customer"。
我希望从收件箱或更好地说,来自所有Outlook文件夹中检索电子邮件。
我的收件箱包含许多子文件夹。由于有很多用户,并且有人可能会将电子邮件放在"个人文件夹"中,因此我可能不知道所有子文件夹的名称。
问题行已经用注释标记出来了。
Sub GetFromInbox()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
'Below is the line I have problem with
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("PRE Customer")
i = 1
x = Date
For Each olMail In Fldr.Items
If InStr(olMail.Subject, "transactions") > 0 _
And InStr(olMail.ReceivedTime, x) > 0 Then
ActiveSheet.Cells(i, 1).Value = olMail.Subject
ActiveSheet.Cells(i, 2).Value = olMail.ReceivedTime
ActiveSheet.Cells(i, 3).Value = olMail.SenderName
i = i + 1
End If
Next olMail
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub