这是我的要求。
我在OUTLOOK中配置了多个帐户。1) 1@email.com (只有一个邮箱) 2) 2@email.com (有多个邮箱。例如: Unix box、Windows Box、Mac box)
这里我的第二个电子邮件帐户有自己的邮箱,并链接到多个邮箱,如UNIX,Windows等。每个邮箱都有自己的收件箱和子文件夹。
现在我需要在Unix邮箱(收件箱)中选择一个文件夹,然后运行代码在文件夹旁边执行一些操作。
这是我的资料
For Each oAccount In Application.Session.Accounts
If oaccount ="1@email.com" then
Set folder = ns.GetDefaultFolder(olFolderInbox) ' here it selects the inbox folder of account.
For each item in folder.items
Code goes here
next
end if
next这适用于单个邮箱帐户,但当我对多个邮箱帐户执行此操作时,它不起作用。
任何帮助都将不胜感激。
发布于 2015-12-02 06:37:20
扩展了DanL的建议,循环通过ns.Folders,因为我不知道你是否理解它。
Option Explicit
Sub accTopFolder()
Dim oAccount As Account
Dim ns As Namespace
Dim fldr As folder
Dim item As Object
Dim inbx As folder
Set ns = GetNamespace("MAPI")
For Each oAccount In Session.Accounts
Debug.Print vbCr & "oAccount: " & oAccount
'
For Each fldr In ns.Folders
' Shows all the names so you can replace "test"
Debug.Print " top folder: " & fldr.name
If fldr = "test" Then
Set inbx = fldr.Folders("Inbox")
'inbx.Display
For Each item In inbx.Items
Debug.Print " item .Subject: " & item.subject
Next
Exit For
End If
Next
Next
Set inbx = Nothing
Set ns = Nothing
End Sub发布于 2015-11-27 18:06:31
您可以使用Account的DeliveryStore属性来获取其收件箱。例如:
Dim ns As NameSpace
Set ns = Application.Session
Dim acc As Account
Dim f As Folder
For Each acc In ns.Accounts
... Preconditions here ...
Set f = acc.DeliveryStore.GetDefaultFolder(olFolderInbox)
... Now, do some looping ...
Nexthttps://stackoverflow.com/questions/33953386
复制相似问题