Friday, May 01, 2009

Outlook efficiency

I'm back on Outlook at work, and yes, I really, really miss Gmail as my work e-mail, but that's a topic for a different day.  One thing that I find really productive about GMail is the single key to archive a message ('y' for those of you keeping score).

So how can I do this in Outlook 2007?   I'll give you the code, but you'll have to monkey with the Macro security settings (now that they are already set up, I can't reproduce the steps until I try this on somebody else's machine, which I will do shortly).

First, create a folder where you are going to move all of your mail.  I call mine "Archive".
Then go to "Tools > Macro > Visual Basic Editor"
Then type the following code in:

Option Explicit
Sub MoveItems()
Dim Messages As Selection
Dim Msg As Object ' Since we can't be sure what has been selected.
Dim NamSpace As NameSpace
    Set NamSpace = Application.GetNamespace("MAPI")
    Set Messages = ActiveExplorer.Selection
    If Messages.Count = 0 Then
        Exit Sub
    End If
    For Each Msg In Messages
      If (Msg.Class = olMail) Or _
      (Msg.Class = olMeetingRequest) Or _
      (Msg.Class = olMeetingResponseNegative) Or _
      (Msg.Class = olMeetingCancellation) Or _
      (Msg.Class = olMeetingResponsePositive) Then 
          Msg.Move NamSpace.Folders("Mailbox - David Pinkus").Folders("Archive")
      End If
    Next
End Sub

PLEASE Replace the "Mailbox - David Pinkus" above with your actual mailbox name.  It's usually pretty obvious from the folder structure.

Also, I only included a few other types above, you may get items that you also want to move.  I included the elaborate constant names for readability, in case I wanted to do something else with these objects.  

So you're almost done.   Save what you did and return to Outlook.

Then go to "Tools > Customize" and choose the "Commands" tab.   You should see your Macro listed.  Click and drag it to one of your toolbars where it will become a button.  

I rename mine to "Muuve" and put an ampersand in front of the first "u" so that the button becomes "Muuve".  Then  you can simply press Alt-U and move the message to your Archive folder.

I'm still getting a "Macro warning" the first time I run it during a session, but will eventually get around to fixing that...




3 comments:

BJ Johnston said...

Ok, that's cool but wouldn't it make just as much sense to set up rules in Outlook to do the same thing?

For instance, I get notices from ImageNow everytime someone in our group gets one, that's a lot of notices. So I created a rule in Outlook that automatically routes them to my Delete folder without me ever having to touch them.

Unknown said...

Thanks David, all of it worked. I did have to restart Outlook to get it to start working so you might want to make a note of that.

knwpsk said...

A while back (and a couple of Outlook versions ago), I was trying to figure out how to automate the painful task of assigning an archive location to many Outlook folders. Outlook (apparently) didn't expose the folder structure to VBA, so I couldn't traverse the structure programmatically/recursively.

I see in your code you accessed a folder by name. Does this mean you can do more with it? Can one folder give up the names of subfolders by some method?