2
votes

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?

1
Do you get any errors while accessing such folders manually in Outlook?Eugene Astafiev

1 Answers

1
votes

Keep in mind that if the delegate default folders are cached (in the primary mailbox's OST file), the sub folders will not be present.

Try to turn caching off for the delegate folders - uncheck the "Download shared folders" checkbox on the Advanced tab of the Exchange account properties dialog.