I am trying to extract information from sub-folders of a shared Outlook inbox.
When I set the folder to the shared inbox (olFolderInbox) the code works perfectly, however, when I set it to a sub-folder, the code will sometimes fail. I ensured that the sub-folder name was correct.
Here is my code:
Dim OutlookNameSpace As Outlook.Namespace
Dim OutlookFolder As Outlook.Folder
Dim OutlookMail As Outlook.MailItem
Dim ObjOwner As Outlook.Recipient
Set OutlookNameSpace = Outlook.Application.GetNamespace("MAPI")
Set ObjOwner = OutlookNameSpace.CreateRecipient("[email protected]")
ObjOwner.Resolve
If ObjOwner.Resolved Then
Set OutlookFolder = OutlookNameSpace.GetSharedDefaultFolder _
(ObjOwner, olFolderInbox).Folders("FolderName")
End If
The error message is:
"Run-time error '-2147221233 (8004010f)':
The attempted operation failed. An object could not be found."
The debugging tool highlights the line where I tried to set the sub-folder as the Outlook Folder.
When I comment out: .Folders("FolderName")
the macro runs fine.
Why does this code sometimes fail?