Welcome to Chewy's Blog Sign in | Join | Help


  • Xobni outlook add-in for your inbox

    Supported by: 8toInfinity

Outlook Macro to Move an Email to Folder

When I took on my new job recently (about 3 months ago), I had no idea how much email I would be getting.  Needless to say… keeping my head above the “email water” has been consuming every free moment I have.  Be it on the airplane or during the weekend when the misses is still asleep.  


The good news is… I’m getting better and have put together a (debatably) decent email management system.  The center of it is moving an email from my inbox to subfolders with marcos and shortcut keys.


Here is a copy of the macro I put together that’ll move the selected email item to a sub-folder.  For each subfolder you want to move to… you need to create another macro.  After you have tested the macro… add it to the tool bar and mark it with a shortcut key.  Then, you can simply keyboard your way through your emails moving them one by one to a “for action” folder or “for review” folder.


Sub MoveSelectedMessagesToFolder()

On Error Resume Next



    Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder

    Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem



    Set objNS = Application.GetNamespace("MAPI")

    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)

    Set objFolder = objInbox.Folders("_Reviewed")

'Assume this is a mail folder



    If objFolder Is Nothing Then

        MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"

    End If



    If Application.ActiveExplorer.Selection.Count = 0 Then

        'Require that this procedure be called only when a message is selected

        Exit Sub

    End If



    For Each objItem In Application.ActiveExplorer.Selection

        If objFolder.DefaultItemType = olMailItem Then

            If objItem.Class = olMail Then

                objItem.Move objFolder

            End If

        End If




    Set objItem = Nothing

    Set objFolder = Nothing

    Set objInbox = Nothing

    Set objNS = Nothing

End Sub


Posted: Wednesday, April 12, 2006 1:34 PM by Chewy Chong


brashs said:


Great little piece of code - very helpful and almost exactly what I was looking for however I have a problem:

Q: I'm running on an exchange server so my Inbox is not local. The code as written directs all mail to a specified folder under the primary inbox folder (in your code it was "_Reviewed"). How do I change the macro to move the message to an archive folder under my "Personal Folders" which are stored on my local drive?

Set objFolder = objInbox.Folders("_Reviewed")

Any insight (or better yet an example of code) would be much appreciated.


# November 9, 2007 12:50 AM

scottpbutler said:

This is an AWESOME macro.  One question though.  I access Gmail via IMAP in Outlook 2007.  Then I have loaded all of my other POP accounts into Gmail and set-up a label that labels each message when it comes in based on the account it comes in through.  This effectively turns all of my POP e-mail accounts into IMAP accounts.

This does two great things for me: allows me to "file" mail via Gmail's web-based interface and not have to file it again when I get back to my computer (like I would have to do with most POP-based accounts with web access) and it allows me to "file" mail via Gmail's mobile application on my Blackberry (unless you are using the Blackberry Enterprise Server for Outlook--which I am not--the current Blackberry mail system does not allow you to file mail from the device).  So both of those save me a TON of time.  I can be sitting in a cab and reading/filing messages and then get back to my desk and not have to deal with them a second time.

So, here's my question.  This macro ROCKS, but is there a way to tell it to file the message into the "All Mail" folder in the "Gmail" PST rather than the "Archive" folder in the "Personal Folders" PST?

If anyone can figure that out, you are awesome!

# March 25, 2008 2:50 AM

bsorenson said:

We've got about 1000 users that currently have their Auto Archive folder set to their profile location and we need to move it to a mapped drive on M:\ArchiveMail.pst.  Is this possible through a Macro that could run at Outlook start up?



# July 31, 2008 10:58 AM


RE: Moving to Personal Folders...


Set objFolder = objInbox.Folders("_Reviewed")


Set objFolder = objNS.Folders.Item("Personal Folders").Folders.Item("Archive").Folders.Item("2008")

works for me.  Assuming you wish to push the mail into "Personal Folders -> Archive -> 2008"


# October 2, 2008 10:56 PM


RE: Moving to Personal Folders...


Set objFolder = objInbox.Folders("_Reviewed")


Set objFolder = objNS.Folders.Item("Personal Folders").Folders.Item("Archive").Folders.Item("2008")

works for me.  Assuming you wish to push the mail into "Personal Folders -> Archive -> 2008"


# October 2, 2008 10:56 PM

steve_B said:

I am trying out this macro in office 2007 and have noticed that when I use my nifty buttons the time and date stamps of the messages are not preserved.  Also, when opening the message it opens as a message that "has not yet been sent."  Is there a way to have the macro use Outlook's built in "move to a folder" function or another way to preserve this information?

# October 29, 2008 1:44 AM

chiefroca said:

Hello, I am using your code it works fantastic. I have been trying to utilize it on a microsoft exchange mailbox that is NOT the default mailbox and I can not get it to work... I think the problem is with the following code:

 Set objNS = Application.GetNamespace("MAPI")

   Set objInbox = objNS.GetDefaultFolder (olFolderInbox)

The name of the mailbox I need to move the message from is "Mailbox - Phoenix, CPC" (FYI: this is not the default mailbox)

   Set objFolder = objInbox.Folders("_Inbox to be worked")

I can get the message to move from the above mailbox, but it will only move to the folder if it is a default mailbox folder such as:

Mailbox - Caleb>_Inbox to be worked

It will not move to from the "Mailbox - Phoenix, CPC" inbox to the folder that is titled "_Inbox to be worked" within that mailbox

I have been digging for weeks to get this done. ANY help would be extreemly welcome

# May 12, 2009 9:45 AM

cnewman65 said:

This is great, can you create a macro to move email to a folder when I close outlook?

e.g. Move emails from helpdesk@me.com to a folder called !HelpDesk

# May 15, 2009 2:21 AM

andrek said:

If you want to move email to a nested folder, replace Set objFolder = objInbox.Folders("_Reviewed") with Set objFolder = objInbox.Folders.Item("Level_1_Folder_Name").Folders.Item("Level_1_Folder_Name").Folders.Item("Level_1_Folder_Name")

# August 27, 2009 8:57 AM

daniel jones said:

how would you replace the below if you wanted to move the message into a Public Folder instead of a personal folder?

Set objFolder = objNS.Folders.Item("Personal Folders").Folders.Item("Archive").Folders.Item("2008")

# September 17, 2009 11:16 PM

daniel jones said:

Also curious, how would you move from one public folder to another public folder?

Thanks guys!

# September 17, 2009 11:27 PM

rlott1906 said:

The macro works great but I have a problem.  How do you move a Read and/or delivery receipt email.  Those emails(reports)don't move.

# December 10, 2009 4:23 AM

DevilzAdvocate said:


i moved my mails to my desired folder but it also changes original date and time when i received the mail. how can i retain my original date and time of mail while moving all my mail to my other folder

# February 3, 2010 12:47 AM
Anonymous comments are disabled