Joe Patrick
Joe Patrick

Reputation: 51

How to move Outlook subfolder to a different parentfolder with Excel VBA

How do I move an Outlook subfolder (and all items in it) to a different parent folder?

Example:

Subfolder to move: Example Event 2017

EXISTING: Outlook\Personal Folders\Audits\Example Event 2017

AFTER CODE RUNS: Outlook\Personal Folders\Audits\Past Events\Example Event 2017

Thank you!

Upvotes: 0

Views: 781

Answers (1)

Joe Patrick
Joe Patrick

Reputation: 51

In Excel, this will move the subfolder "test" from its parent folder "new" to make it a subfolder of "processed". (needs reference to Outlook)

Sub moveSubFolderToNewFolder()

    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.Namespace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objFolder As Folder

    Set objOutlook = Outlook.Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("new").Folders("test")
    Set objDestFolder = objNamespace.GetDefaultFolder(olFolderInbox).Folders("processed")

    objFolder.MoveTo objDestFolder

    Set objDestFolder = Nothing

End Sub

Upvotes: 1

Related Questions