luskbo
luskbo

Reputation: 165

Outlook VBA 2013 Access Parent Folders

Okay, I was reading a tutorial on how to access parent folders outside of the Inbox and noticed that it was using "Set". To my knowledge, this command is deprecated and seems so whenever I have tried to use it in my code.

http://blogs.technet.com/b/heyscriptingguy/archive/2006/08/03/how-can-i-get-access-to-a-mail-folder-that-isn-t-a-subfolder-of-my-outlook-inbox.aspx

    ' Set Outlook parameters
    objOutlook = CreateObject("Outlook.Application")
    iNameSpace = myOlApp.GetNamespace("MAPI")                       ' Set current NameSpace
    Dim oExp As Outlook.Explorer
    Dim oSel As Outlook.Selection
    oExp = objOutlook.ActiveExplorer
    oSel = oExp.Selection
    Dim strFolderName As Object
    Dim objInbox As Outlook.Folder
    Dim objMailbox As Outlook.Folder
    Dim objFolder As Outlook.Folder


    Const olFolderInbox = 6
    objInbox = iNameSpace.GetDefaultFolder(olFolderInbox)
    strFolderName = objInbox.Folders.Parent()
    objMailbox = iNameSpace.Folders(strFolderName)
    objFolder = objMailbox.Folders("Europe")

When trying the code above, I get a type error: Additional information: Type mismatch, on this line:

    objMailbox = iNameSpace.Folders(strFolderName)

When I change this to an "Object", I get the same error.

Any Idea what I am doing wrong?

Upvotes: 0

Views: 2049

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66306

To access the parent of the Inbox folder, try iNameSpace.GetDefaultFolder(olFolderInbox).Parent

To access a folder on the same level as the Inbox, try iNameSpace.GetDefaultFolder(olFolderInbox).Parent.Folders.Item("The Folder name")

Upvotes: 1

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

The following code will not work.

 strFolderName = objInbox.Folders.Parent()

The Folders collection does't provide the Parent method.

 objMailbox = iNameSpace.Folders(strFolderName)

The Folders property doesn't accept an object arguments.

Upvotes: 0

Related Questions