【发布时间】:2015-10-04 03:52:05
【问题描述】:
我正在使用以下 vba 代码检查具有特定主题标题的任何电子邮件。
问题是当我需要它来检查我的其他电子邮件帐户 NewSuppliers@Hewden.co.uk 的收件箱时,它会检查我的默认 Outlook 收件箱文件夹
有人可以告诉我如何做到这一点吗?提前致谢
Sub Macro1() Set olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Dim myAttachment As Outlook.Attachment
Dim I As Long
Dim olMail As Variant
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items
Set olMail = myTasks.Find("[Subject] = ""New Supplier Request: Ticket""")
If Not (olMail Is Nothing) Then
For Each myItem In myTasks
If myItem.Attachments.Count <> 0 Then
For Each myAttachment In myItem.Attachments
If InStr(myAttachment.DisplayName, ".txt") Then
I = I + 1
myAttachment.SaveAsFile "\\uksh000-file06\Purchasing\NS\Unactioned\" & myAttachment
End If
Next
End If
Next
For Each myItem In myTasks
myItem.Delete
Next
Call Macro2
Else
MsgBox "There Are No New Supplier Requests."
End If
End Sub
outlook文件夹结构:
account1@hewden.co.uk
Inbox
Drafts
Sent
NewSuppliers@hewden.co.uk
Inbox
Drafts
Sent
【问题讨论】:
-
我已经更新了我的答案,以解释我所说的“相同级别”是什么意思......另外......你使用的是什么版本的 Outlook?
-
那是 Exchange 邮箱吗?是否已在 Outlook 中打开?