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

News







  • 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

    Next

 

 

    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

Comments

brashs said:

Chewy:

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.

Thanks.

# 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?

Thanks,

Bill

# July 31, 2008 10:58 AM

CAMURPHY said:

RE: Moving to Personal Folders...

Replacing:

Set objFolder = objInbox.Folders("_Reviewed")

with

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"

HTH

# October 2, 2008 10:56 PM

CAMURPHY said:

RE: Moving to Personal Folders...

Replacing:

Set objFolder = objInbox.Folders("_Reviewed")

with

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"

HTH

# 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
Anonymous comments are disabled