Here is my requirement.
I have multiple accounts in my OUTLOOK configured. 1) 1@email.com (only one mailbox) 2) 2@email.com (Multiple mailbox\'s are there. ex: Unix
Expanding on DanL's suggestion to loop through ns.Folders as I cannot tell whether you understood it.
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
You can use the DeliveryStore property of the Account
to get its inbox. For example:
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 ...
Next