Accessing subfolders within shared mailbox RRS feed

  • Question

  • Hello,

    I have organized some of my shared mailbox items into subfolders. I have some VBA code that should access a specific subfolder and write the results into an Excel workbook.

    I'm getting stuck accessing the subfolders - Outlook tells me that the object could not be found.

    Currently, I have only one level of subfolders below the Inbox. Below is a the snippet I am using to access the subfolder

    ' set up references to active Outlook
    Set oOL = New Outlook.Application
    Set oNS = objOL.GetNamespace("MAPI")
    Set oFolder = objNS.Folders.Item("Inbox").Folders.Item("Undeliverable") 

    Any help would be appreciated.


    Thursday, February 6, 2014 4:03 PM


All replies

  • Hello David,

    Do you use the cached exchange mode? Most probably you work offline when you get an error. Is it the case?

    I'd recommend breaking the long chain of calls into separate lines of code:

    Dim folders as Outlook.Folders
    Dim inboxFolder as Outlook.Folder
    Dim inboxFolders as Outlook.Folders
    Dim undelFolder as Outlook.Folder
    Set folders = objNS.Folders
    Set inboxFolder = folders.Item("Inbox")
    Set inboxFolders = inboxFolder.Folders
    Set oFolder = inboxFolders.Item("Undeliverable") 

    Thus, you may find what line of code fires the exception. Also please note that you can use the GetDefaultFolder method of the Namespace class for getting one of the default folders. The Namespace class also provide the following methods that you may find useful:

    OpenSharedFolder - Opens a shared folder referenced through a URL or file name. Can be used in Outlook 2007+.

    GetSharedDefaultFolder - Returns a Folder object that represents the specified default folder for the specified user.

    Thursday, February 6, 2014 5:02 PM
  • Yes, I'm in Cached Exchange Mode.

    So, I broke it down to make it more manageable

    Set oNS = oOL.GetNamespace("MAPI")
    Set oFld = oNS.Folders.Item("Report Server")
    Set oSfld = oFld.Folders.Item("Inbox")
    Set oSfld2 = oSfld.Folders.Item("Reports")
    Outlook still tells me that the object couldn't be found. I tried iterating through the folders collection at the "inbox" level but no subfolders were returned which is strange.

    Thursday, February 6, 2014 6:48 PM
  • Dave,

    What Outlook version do you have installed?

    Please take a look at the By default, shared mail folders are downloaded in Cached mode in Outlook 2010 and Outlook 2013 article. What value do you have set for the CacheOthersMail key on the PC?

    Also please take a look at the Detecting if ‘Download Shared Folders’ is Checked in Outlook article.

    Thursday, February 6, 2014 6:55 PM
  • I'm using Outlook 2010 32-bit.

    I had to create the "CacheOthersMail" key on my machine, but it looks like it will only work for newly created profiles. So, will I have to delete the shared mailbox profile and then add it back in?

    I'll take a look at the 2nd link you posted.


    Thursday, February 6, 2014 7:12 PM
  • If using Redemption is an option, it always opens shared mailboxes in the online mode.

    set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set Inbox = Session.GetSharedDefaultFolder("user name", olFolderInbox)
    set SubFolder = Inbox.Folders.Item("Reports")

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, February 6, 2014 7:28 PM
  • I restarted my machine and it looks like the changes took. Thanks for the resources!
    Thursday, February 6, 2014 9:47 PM
  • Dmitry, this looks like an awesome resource. I will definitely look into this, unfortunately I don't have admin rights on my machine (it sucks, I know).
    Thursday, February 6, 2014 9:47 PM