Move Messages to Folders with Outlook VBA

Let’s say your email management approach is to save important messages to a folder other than your Outlook Inbox. You might save messages from outside vendors to a folder named “Vendor Documents” or messages related to corporate policy to a “Policies” folder. Here’s an Outlook VBA macro that helps to file those messages from your Inbox in a single click:

Sub MoveToFolder(folderName)

 mailboxNameString = "Mailbox - Firstname Lastname"

 Dim olApp As New Outlook.Application
 Dim olNameSpace As Outlook.NameSpace
 Dim olCurrExplorer As Outlook.Explorer
 Dim olCurrSelection As Outlook.Selection

 Dim olDestFolder As Outlook.MAPIFolder
 Dim olCurrMailItem As MailItem
 Dim m As Integer

 Set olNameSpace = olApp.GetNamespace("MAPI")
 Set olCurrExplorer = olApp.ActiveExplorer
 Set olCurrSelection = olCurrExplorer.Selection

 Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName)

 For m = 1 To  olCurrSelection.Count
    Set olCurrMailItem = olCurrSelection.Item(m)
    Debug.Print "[" & Date & " " & Time & "] moving #" & m & _
                ": folder = " & folderName & _
                "; subject = " & olCurrMailItem.Subject & "..."
    olCurrMailItem.Move olDestFolder
 Next m

End Sub

Some customizations are necessary to make this all work for your email system. First, copy-and-paste the program to the Visual Basic Editor in Outlook (which you can open with Alt-F11). You’ll need to create a new VB Module (use the Insert->Module menu choice) to hold the macro if you don’t already have custom Outlook macros defined.

Second, the text highlighted in the blue bold font needs to be edited for the name of your Exchange mailbox; you can usually find the name of your mailbox on the left side of the Outlook window at the top, it starts with “Mailbox” like in the example above.

Third, you’ll need to add other VBA macros which call the MoveToFolder() macro with the correct folder name passed as  a parameter. For example, we might create two additional macros one each for the Vendor Documents and the Policies folders; the macro for Vendor Documents might be called MTV() and the Policies folder macro MTP():

Sub MTV()
 MoveToFolder ("Vendor Documents")
End Sub

Sub MTP()
 MoveToFolder ("Policies")
End Sub

(Note, the destination folders should already exist in your Outlook folder list.)

The last step is to assign the macros to Outlook toolbar buttons so you can move the selected messages in your Inbox to the appropriate folders with a click. If you’re managing multiple destination folders, and you created multiple macros (one for each folder), you can also create a new toolbar to organize all your MoveToFolder() macros. Here’s a Microsoft Knowledge Base article that describes how to assign Outlook VBA macros to toolbar buttons: How to Assign a Macro to a Toolbar Button.

The MoveToFolder() macro will work on a single selected message, or a group of messages selected in a sequential range (with a Shift-Click), or a non-sequential range (with Ctrl-Clicks). Also, an activity message will be written to the VBA Editor’s Immediate Window (which is opened with Ctrl-G) so you can go-back and view MoveToFolder() activity. A total win for email convenience, give it a try.



  1. George says:

    Hiya, great idea, but didn’t work for me. The movetofolder macro didn’t pop up in my list of macros. Should I have adapted the foldername entries?

  2. This is great, also for Outlook 2010 – trly a time-saver. However, I am struggling to find the right syntax for moving to subfolders. What if “Vendor Documents” contains subfolders for different vendors? How can I then append the subfolder name correctly to the “MoveToFolder (“Vendor Documents”)” line of the code? Your advice on tis would be greatly appreciated!

  3. saieva says:

    The syntax should be, for example:

    MoveToFolder(“Vendor Documents\Apple”)

    Happy to hear it’s working Ok for you, and thanks for the confirmation for Outlook 2010.


  4. saieva says:


    Did you create a new module for the code (ie, the step where you choose the Insert->Module menu choice in the Outlook VBA Editor)?


  5. Thanks for the subfolder reply! Unfortunately, it doesn’t work. There’s a run-time error ‘-2147221233 (8004010f)’ and the Debugger points to a line in the top syntax:

    Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName)

    Does this need to be modified for the subfolder syntax to work in each macro?

    With Outlook 2007 I used a different syntax( that handles subfolders, but which doesn’t work with Outlook 2010… Also, I much prefer yours since the code for each folder Macro is so short in comparison.

  6. Harald says:

    Did you get it to work? I have the same problem, using outlook 2007.

  7. Harald says:

    Replacing the specific errorline with:

    Set olDestFolder = Application.GetNamespace(“MAPI”).Folders(folderName)

    Solves the issue (at least for Outlook 2007)

  8. saieva says:

    Thanks for the fix Harald. I don’t have access to an Exchange Server at this point so I can’t test these changes. Based on the change though, I would double-check the value of the mailboxNameString variable; it may be incorrect or have a typo in its value.


  9. I got the craigmurphy code that I linked to above to work for 2010 too, so I opted for that one. I will try saieva’s code again with Harald’s correction. Thanks!

  10. Dominik says:

    thanks for this. Is there also a way to build in a trigger that every message that I’m sending is checked in the “from” field and if the right one applies is is moved to a specific folder?

  11. saieva says:

    Hello Dom,

    I’m sure it’s possible from VBA but I never looked into it. Outlook has a rule for processing messages after sending. Would the built-in functionality meet your needs?


  12. Dominik says:

    Hi Saieva,
    thanks for the comment.
    Unfortunately that won’t work cause I’m sending from several inboxes and there is no specific rule I know of to identify an eMail by the person that has send it (I’m using Outlook 2007). Have tried quite a bit around but the only solution I have would be to take a macro that destinguishes which eMail to take from the “from field”. Haypp to be taught otherwise though.
    PS: I’d try to work around it myself but my VBA knowledge just doesn’t cover that…

  13. saieva says:

    I’m sure it’s possible to create such a trigger in VBA, but I don’t have a solution I can send you. The move to folder code posted can be used in a manual fashion after the message is sent. For example, you can open the Sent Items folder, select messages, and run the macro to move to destination folders. However, that approach would not be triggered automatically.


  14. Prakash says:

    Saiva – Thank you so much for this code, unfortunately this doesnt work for me in 2003 version of outlook.
    Can you please help mw out fix this?

  15. Prakash says:

    the problem is –
    There’s a run-time error ‘-2147221233 (8004010f)’ and the Debugger points to a line in the top syntax:

    Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName)

    Does this need to be modified for the subfolder syntax to work in each macro?

  16. saieva says:

    Yes, the script needs to be setup for your mailbox. Specifically, this variable needs to be defined in the script:

    mailboxNameString = “Mailbox – Firstname Lastname”

    There are instructions in the blog posting.


  17. Peter says:

    Thanks for the script. I am using Outlook 2007 and to access subfolder of my Inbox I had to make one change to your code. Hopfully this helps others who had issues doing the same:

    Set olDestFolder = olNameSpace.Folders(“Mailbox – Smith, Joe”).Folders(“Inbox”).Folders(folderName)

  18. saieva says:

    Great. Thanks for the feedback Peter.



  19. digitalreins says:

    Thanks, got me close to what I was looking for. I changed it a little to dynamically pick the folders that you move messages from and to.

    My updated code is posted at

    The code here definitely helped me on the road toward what I needed.

  20. saieva says:

    Great. Thanks for the reference and for also making your solution public.


  21. Someguy. says:

    Like others I kept having problems with

    Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName)

    It seemed like “mailboxNameString” was to fault, but I couldn’t work out the problem. However another site (I forget which) provided a solution which did away with the mailbox name altogether:

    Set olDestFolder = olNameSpace.GetDefaultFolder(olFolderInbox).Folders(folderName)

    On a separate note (and this was slightly covered by another comment), it appears that in a heirarchy of folders you have to specify each one all the way down, eg:

    Set olDestFolder = olNameSpace.GetDefaultFolder(olFolderInbox).Folders(“Dairy”).Folders(“Milk”).Folders(“Semi-skimmed”)

  22. Ronald says:

    how should I change the code at the top if I wanted to make a copy of an email in another folder, instead of moving the email? I tried changing “move” to “copy”, but that doesn’t work.

  23. saieva says:

    Hello Ronald,

    I haven’t tested but you can try to change this line in the For loop (right before the Next statement):

    olCurrMailItem.Move olDestFolder


    olCurrMailItem.Copy olDestFolder


  24. Ronald Mook says:

    Thanks for your quick reply!
    I tried to use copy instead of move, but that doesn’t work. Outlook 2010 gives an error message after reaching this line of code with Copy. It says Object not supported by this method.

  25. Ronald says:

    thanks for your quick reply! (I also tried to use my phone to reply, but I think I did something wrong).

    I tried to replace “Move” with “Copy”, but I get an error message telling that the object is not supported by the method (Outlook 2010) everytime I pass this line of code.

    However! I found out the email is indeed copied. But the copy is placed in the inbox, not in the destination folder.
    Good enough for me, if I can move the copy to my destination folder as the next step. Working on that now.

    By the way, something that made me hesitating a while (I know just enough VBA to be dangerous…….), is the mailboxnamestring stuff. I kept thingking I needed something like your example (“mailbox – firstname lastname”), but I could only find “persoonlijke mappen” on my screen (I’m Dutch, by the way). I thought you gave some kind of syntax, where I absolutely needed the term “mailbox” and so on.
    It turns out it is less complicated than I thought (it often is). I could just use “persoonlijke mappen”.


  26. Ronald says:

    It works!

    This is the code I need (It copies an email with attachments, if there are any, in the inbox and then moves the original email with attachments to the destination folder I made).

    For m = 1 To olCurrSelection.Count
    Set olCurrMailItem = olCurrSelection.Item(m)
    olCurrMailItem.Move olDestFolder
    Next m

    (I removed the debug.print part, as it is not needed to make this work)


  27. saieva says:


    I just tested, it can be accomplished in two steps:

    olCurrMailItem.Move olDestFolder

    So add the copy before the move. This approach tested Ok for a single mail item, an adjacent (shift-click) selection, and non-adjacent (ctrl-click) selection.


  28. Hashmi says:

    Can I use this Macro in stand alone Outlook 2007. I don’t have an Exchange Server.What change do I have to make to “mailboxNameString = “Mailbox – Firstname Lastname” I am very new to VBA so apologies if my assumption is not obvious.

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s