I am trying to get Emails from a folder in Microsoft Outlook from a VBA module in Microsoft Outlook. This just fine for one of my accounts, but not for another.
Only one account is available when I set the namespace object, even though I can see three in Outlook.
Any ideas why some accounts would not show up would be appreciated.
Public Function get_Outlook_Account_By_Name(strMailboxName As String) As outlook.Account
Dim olApp As outlook.application
Dim olNamespace As outlook.NameSpace
Dim olAccount As outlook.Account
Set olApp = New outlook.application
Set olNamespace = olApp.GetNamespace("MAPI")
For Each olAccount In olNamespace.Accounts
If olAccount.DisplayName = strMailboxName Then
Set get_Outlook_Account_By_Name = olAccount
Exit For
End If
Next olAccount
Set olApp = Nothing
Set olNamespace = Nothing
End Function