• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Macro to automate the Move to Folder command

Slipstick Systems

› Outlook › Macro to automate the Move to Folder command

Last reviewed on May 2, 2016     26 Comments

An Outlook user had a problem: delegates drafted messages for their managers and needed to save them in the manager's Drafts folder.

If the delegate creates a Draft email (not sent yet) and wants to save it in the manager's Draft folder, there is no easy way to do that. It automatically saves in the Delegate's Drafts folder by default. We tried moving it from the delegate's folder to the manager's folder, but then the manager does not have access to edit it. So we had to copy it, and then delete the copy from the Delegate's folder. This is crazy as it involved many more steps and is not efficient.

They discovered they could use the Move to Folder command to save the Drafts in the manager's Drafts folder and save a few steps. While the Move to Folder command is easy to use, especially when the folder you want to move to is on the MRU list, you can save a step or two by using a macro to move the draft.

Shared mailbox names in the folder listTo use this macro, paste it into a module in the VB Editor then change the Destination folder name. Use the mailbox or data file name as it appears in your folder list; Exchange server mailboxes will use the display name as seen in the GAL.

ribbon buttonOpen a new message form and customize the ribbon or QAT by creating a button for the macro.

Create a draft message then click the button to move it to another folder.

Move to a folder macro

Sub MoveDraftMail()
 
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As MailItem
     
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderDrafts)
    Set objItem = objOutlook.ActiveInspector.currentItem    
    Set objDestFolder = objNamespace.Folders("Mary Reaser").Folders("Drafts")
 
    objItem.Move objDestFolder
               
    Set objDestFolder = Nothing
End Sub

Customize the macro

You can use this macro with other Outlook item types by changing the objItem and folder names. For example, I want to save contacts in my Sharepoint list, so I changed three lines to the following:

Dim objItem As ContactItem

Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderContacts)

Set objDestFolder = objNamespace.Folders("SharePoint Lists").Folders("SPS - Contacts")

To use the currently selected folder as the source folder, use
Set objSourceFolder = objNamespace.ActiveExplorer.CurrentFolder

Dim objItem As Item Type
AppointmentItem
ContactItem
MailItem
NoteItem
TaskItem
GetDefaultFolder types
olFolderCalendar
olFolderContacts
olFolderDeletedItems
olFolderDrafts
olFolderInbox
olFolderJunk
olFolderManagedEmail (Exchange only)
olFolderNotes
olFolderOutbox
olFolderSentMail
olFolderTasks
olPublicFoldersAllPublicFolders (Exchange only)

Permissions

Please note, the user needs to have at least Create permission on the folder they are moving the item to. If the folder is in another person's mailbox, the folder (or the mailbox) needs to be open in Outlook as a shared folder or mailbox.

Give the delegate Author permission on the Drafts folder

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Macro to automate the Move to Folder command was last modified: May 2nd, 2016 by Diane Poremsky
Post Views: 18

Related Posts:

  • Macro to file Outlook email by sender's display name
  • Macro to Move Aged Email Messages
  • Moving Deleted Items
  • Move email items based on a list of email addresses

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Comments

  1. Guy Stewart says

    March 15, 2023 at 5:09 pm

    I am trying to create a macro to move contacts to a sub folder of contacts call piesync, I changed the following lines in the base Macro from Dim objItem As MailItem to Dim objItem As ContactItem the second line from Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderDrafts) to Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderContacts) and the third and final line from Set objDestFolder = objNamespace.Folders("Mary Reaser").Folders("Drafts") to Set objDestFolder = objNamespace.Folders("Test Contact for Piesync").Folders("Contacts"). When I go to test it i receive "Invalid outside procedure".

    Reply
  2. ^Corentint says

    April 24, 2021 at 1:05 pm

    Sorry, I should have said:

    Hello,

    Is there a way this can be adapted to non mapi folders?

    Thank you in advance

    Corentint

    Reply
    • Diane Poremsky says

      June 9, 2021 at 1:02 am

      If you mean will it work with any outlook folder, yes.

      If you mean file system folders, its possible to do but not with this macro. You need to use the FileSystemObject

      Reply
  3. Shubham says

    June 11, 2018 at 1:37 am

    I Want my reply all messages i.e same subject , to move to a other folder keeping just the latest one in my inbox. And i want all mail no deletions. Can u suggest ways for this

    Reply
    • Diane Poremsky says

      June 11, 2018 at 10:56 am

      The macro at https://www.slipstick.com/developer/delete-older-messages-new-message-arrives/ could be tweaked to move messages ot a new folder rather than delete them.

      Reply
  4. Rob Cole says

    November 25, 2017 at 11:40 pm

    I'm trying to modify this macro so that I can take the currently selected folder (which may not have any items in it) and move the entire folder into another. I keep getting "Object doesn't support this property or method" at this line

    Set objSourceFolder = objNamespace.ActiveExplorer.CurrentFolder

    I was able to get a similar macro to work using this:

    Set objSourceFolder = ns.PickFolder

    But would like to avoid having to go through a dialog box to pick the folder when I already have the folder selected in Outlook.

    Would appreciate any help!

    Reply
    • Diane Poremsky says

      November 26, 2017 at 8:28 am

      So you want to move the folder itself, not a message? I’ll take a look.

      Reply
  5. Jason j says

    February 20, 2017 at 12:17 pm

    hI, i love this macro and the tutorials you put out.
    is there a way to modify this so that it moves folders in a different invox that is not the default inbox (i have more than one inbox in my outlook to manage)?

    thanks

    Reply
    • Diane Poremsky says

      May 25, 2017 at 8:11 pm

      Sorry I missed this earlier. Moving to another mailbox requires identifying the folder... this page has some information - https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/ - you'll need to use getfolderpath function or the method to use a shared folder in Set objDestFolder =.

      For example, i have two accounts in my profile (listed in file, account settings) and would use this to move it into a folder in the second mailbox: Set objDestFolder = GetFolderPath("alias@outlook.com\Test")

      Reply
      • cara says

        November 30, 2021 at 9:36 pm

        This is not working for me. I am trying to archive emails from multiple email accounts in the same profile to a Gmail "All Mail" folder in one specific account. The emails get moved to All Mail, but in their current account.

        I am using the GetFolderPath function that you provided, and
        Set destFolder = GetFolderPath("myemailaddr@gmail.com\[Gmail]\All Mail")

        Is this the correct way to reference a Google All Mail folder?

      • Diane Poremsky says

        December 1, 2021 at 1:14 pm

        If this is the account you are moving into - myemailaddr@gmail.com - and the All Mail folder is visible, it should work.

        Check the Sync issues folder in the myemailaddr account - Ctrl+6 to show the folder list - its near the bottom of the folder list in that account. Any messages pertaining to the messages you are trying to move?

        also, if they are all Gmail accounts, you might have messages in the all mail folder sin both accounts, depending on your gmail.com settings.

  6. Tom Benardo says

    December 1, 2016 at 9:23 am

    hi! this is very handy. I want to be able to move (not copy) a message to a task. I tried to use this macro, replacing destination with "Tasks" folder but I got the message it is not supported. Any ideas?

    Reply
  7. Victor Ivanidze says

    March 1, 2016 at 5:48 am

    There exists a third-party tool that solves this problem:
    https://ivasoft.com/cooldraft.shtml

    Regards,
    Victor

    Reply
  8. Bartoch says

    August 10, 2015 at 9:46 am

    I have make a script for copy a contact list to a contact list in the public folder but if i'm not on the contact source , the macro don't work, i don't know why, thx.

    I things the error come from:
    Set objItem = Application.ActiveExplorer.Selection.Item(1)

    Sub Movecopycontacts()

    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As ContactItem

    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderContacts)
    Set objItem = Application.ActiveExplorer.Selection.Item(1)
    Set objDestFolder = objNamespace.Folders("Public folder - oky@test.com").Folders("all public folder").Folders("test")

    objItem.Move objDestFolder

    Set objDestFolder = Nothing
    End Sub

    Reply
  9. chrisbr40 says

    December 23, 2014 at 10:41 am

    I'm an Outlook 2013 user but spend a fare amount of time with Outlook for Mac for one and only one feature; Message\Move\Choose Folder and its shortcut key. My work requires me to use hundreds of Outlook folder. The time saved by being able to select a message in the Inbox, hit Shift-Command-M, and start typing the folder name is immense.

    Is there way to replicate this function in Outlook 2013?

    Reply
    • Diane Poremsky says

      December 29, 2014 at 12:18 am

      Outlook 2013's shortcut is Ctrl+Shift+V - you can only type the first letter of a folder to jump to it, not the folder name. Plus, you could use Quick Steps to move messages.

      Reply
  10. shiv says

    November 24, 2014 at 12:29 pm

    Hi, can you plz help.

    the for atmt is running only 3 time and exits,

    Reply
    • Diane Poremsky says

      November 24, 2014 at 1:35 pm

      What macro are you using?

      Reply
  11. Douglas says

    October 1, 2014 at 6:31 pm

    This Worked! Thank you for your help!!!

    Private Sub Application_Startup()
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objVariant As Variant
    Dim lngMovedItems As Long
    Dim intCount As Integer
    Dim intDateDiff As Integer
    Dim strDestFolder As String

    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)

    ' use a subfolder under Inbox
    Set objParent = Session.GetDefaultFolder(olFolderInbox)
    Set objManaged = objParent.Parent.Folders("Managed Folders")
    Set objDestFolder = objManaged.Folders("7 Year Retention")

    For intCount = objSourceFolder.Items.Count To 1 Step -1
    Set objVariant = objSourceFolder.Items.Item(intCount)
    DoEvents
    If objVariant.Class = olMail Then

    intDateDiff = DateDiff("d", objVariant.SentOn, Now)

    ' I'm using 7 days, adjust as needed.
    If intDateDiff > 7 Then

    objVariant.Move objDestFolder

    'count the # of items moved
    lngMovedItems = lngMovedItems + 1

    End If
    End If
    Next

    ' Display the number of items that were moved.
    MsgBox "Moved " & lngMovedItems & " messages(s)."
    Set objDestFolder = Nothing

    End Sub

    Reply
  12. Douglas says

    October 1, 2014 at 6:15 pm

    Set objDestFolder = Session.GetDefaultFolder(olFolderInbox).Parent._
    Folders("Managed Folders").Folders("7 Year Retention")

    would take the mail from inbox and place it in the managed folder > 7 year retention folder correct ?

    And I would replace
    Set objDestFolder = objSourceFolder.Folders("@test")
    With the above code to make it work?

    Reply
    • Diane Poremsky says

      October 1, 2014 at 8:04 pm

      I know you've already figured it, but for the benefit of others...

      Correct, you need to replace the original objDestFolder object with one representing the new path. While it will work to put the entire path into one object, it's better to assign each folder to an object and split the path - VBA doesn't like a lot of dots in the object.

      Reply
  13. Douglas says

    October 1, 2014 at 5:30 pm

    I'm hoping someone can help me. I'm trying to make a script that will take mail thats in the inbox and if it is after 60 days move it to my 7 Year Retention folder under Managed Folders in outlook. I have been able to get it to work if i want to move it to another folder under my inbox but not outside of the inbox... Please help.

    Private Sub Application_Startup()

    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objVariant As Variant
    Dim lngMovedItems As Long
    Dim intCount As Integer
    Dim intDateDiff As Integer
    Dim strDestFolder As String

    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)

    ' use a subfolder under Inbox
    Set objDestFolder = objSourceFolder.Folders("@test")

    For intCount = objSourceFolder.Items.Count To 1 Step -1
    Set objVariant = objSourceFolder.Items.Item(intCount)
    DoEvents
    If objVariant.Class = olMail Then

    intDateDiff = DateDiff("d", objVariant.SentOn, Now)

    ' I'm using 7 days, adjust as needed.
    If intDateDiff > 60 Then

    objVariant.Move objDestFolder

    'count the # of items moved
    lngMovedItems = lngMovedItems + 1

    End If
    End If
    Next

    ' Display the number of items that were moved.
    MsgBox "Moved " & lngMovedItems & " messages(s)."
    Set objDestFolder = Nothing

    End Sub

    Reply
    • Diane Poremsky says

      October 1, 2014 at 6:11 pm

      Is it in the same mailbox as your inbox or in a different data file? If Managed Folders is at the same level as your inbox, use this:
      Set objDestFolder = Session.GetDefaultFolder(olFolderInbox).Parent._
      Folders("Managed Folders")

      For a folder under managed folders, you'd add .Folders("Subfolder") under it. If you need to go too far down you should walk down the folders to avoid long strings with a lot of dots.
      Set objParent = Session.GetDefaultFolder(olFolderInbox)
      Set objManaged = objParent.Parent.Folders("Managed Folders")
      Set objDestFolder = objManaged.Folders("SubFolder")

      Reply
  14. Ernesto says

    March 26, 2014 at 1:03 pm

    I changed the code to copy emails to task folder and I am getting a 91 error on line
    Set objItem = objOutlook.ActiveInspector.CurrentItem

    Thte new code is
    Sub CopyToTask()
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As MailItem
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objItem = objOutlook.ActiveInspector.CurrentItem
    Set objDestFolder = objNamespace.GetDefaultFolder(olFolderTasks)
    objItem.Copy objDestFolder
    Set objDestFolder = Nothing
    End Sub

    Reply
    • Diane Poremsky says

      March 27, 2014 at 12:59 am

      .ActiveInspector.CurrentItem works with open items, not selected items. See https://www.slipstick.com/developer/outlook-vba-work-with-open-item-or-select-item/ - you can use .ActiveExplorer.Selection.Item(1) for open items or the GetCurrentItem function for either.

      However, this is erroring on the copy - you are trying to copy a mail item to tasks. You need to use Move instead. Yeah, doesn't make much sense, but it works. :)

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 3

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.