2010 Outlook VBA - Accessing non-default folders

  • I have viewed many threads on this topic, but I just can't get this to
    work for me: Please note that the folder "USPS Compass JE" is on the same
    folder hierarchy level as Inbox

    1. Dim olapp As Outlook.Application
    2. Dim olNameSpace As Outlook.Namespace
    3. Dim olfolder As Outlook.MAPIFolder
    4. Set olapp = CreateObject("Outlook.Application")
    5. Set olNameSpace = olapp.GetNamespace("MAPI")
    6. Set olfolder = olNameSpace.Folders("USPS Compass JE")

    When I look at the folder's properties, it's location is:
    \\Mailbox - Pelkey, Brian

    When I step through the code, I get an error message for the last
    coded line that "An object cannot be found".

    I also have tried:

    Set olfolder = olNameSpace.Folders("Mailbox - Pelkey,Brian/USPS Compass JE")

    AND also the GETFOLDER method which didn't appear to be valid.

    Thanks for any informed help offered.


  • Re: 2010 Outlook VBA - Accessing non-default folders

    Thank you Greg! That appears to work, subject to testing by my internal customer, but I am confident she will have success also.

    I have searched for that answer on the web from many different perspectives, but never hit on an answer that was that closely related to my question.


  • Thank you Greg for the answer!

    To those who are going through hell knowing the answer is there but unable to locate.

    Here is a direct link:

    And here is a working code i used from that link:

    Public WithEvents FolderItems As Outlook.Items

    Public Sub Application_Startup()
    Set objInbox = Session.GetDefaultFolder(olFolderInbox)
    strFolderName = objInbox.Parent
    Set objMailbox = Session.Folders(strFolderName)
    Set objFolder = objMailbox.Folders("Archive")
    Set FolderItems = objFolder.Items
    End Sub

    Public Sub FolderItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    If Item.UnRead Then
    Item.UnRead = False
    End If
    End Sub