Pimping Microsoft Outlook

Posted Mar 18th, 2009 at 11:57 am in Technology

Outlook Pimp Chain

I’m one of the odd people that actually like Outlook. It’s kind of a love hate relationship though. I like it for precisely the reason that many people hate it. It integrates email, calendar, and tasks all into one program. It can also be a beast, especially when you have to go into its settings to tweak things.

One thing I’ve wanted for a long time is the ability to do things with single keystrokes in Outlook. I wanted to hit the letter ‘a’ and have my currently selected email(s) get moved automatically into an archive folder. I wanted to hit ‘r’ to reply to the current email. Things like that.

I recently came across this blog post that got me very close… What this person did is write a macro for Outlook that could archive messages, and then assigned that macro to a button on the toolbar. Outlook let’s you give the macro a shortcut, but unfortunately, it has to be the ALT Key + some other key…

The way to Nirvana lies in a free and wonderful program called AutoHotkey or AHK for short. AHK lets you write small scripts that can do lots of things, one of which is remap keystrokes. So what I did was write an AHK script that takes single keystrokes and sends different keystrokes that Outlook understands.

Update: The good folks at Lifehacker have put up two posts using my techniques. One for adding an archive macro button, the other for adding shortcut keys. They added some new shortcuts to the list, and I’ve taken a few of them and updated my script as well.

Outlook Shortcuts

My script has the following shortcuts:

  • a — archives the selected message(s)
  • j — moves down to the next message
  • shift+ j — selects messages as it moves down to the next message
  • k — moves up to the previous message
  • shift+ k — selects messages as it moves up to the next message
  • f — forwards the current message
  • r — replies to the current message
  • ctrl + r — “replies all” to the current message
  • u — marks the selected message(s) as unread
  • y — marks the selected message(s) as read
  • / — gives focus to the message search box in Outlook

Now this only happens when you’re in Outlook AND when you have an email selected or you’re inside the reading pane reading an email. (After all, my solution wouldn’t be very good if ever time you typed ‘f’ when typing an email your message was opened for forwarding.)

New Mail Shortcut

The other nifty thing my script does is makes the Windows Key + N a shortcut for opening up a new message from anywhere in the computer. Even cooler, if you have a file or files selected when you hit Win + N, then the new message that opens up has those files attached to the email, ready for sending.

Which versions of Outlook does it work in?

The script has been tested in Outlook 2007 on Windows Vista. It will very likely work in Outlook 2007 on Windows XP too. It may work in earlier versions of Outlook, but the code will definitely need some amount of tweaking. (For example, one place refers to a path specific to Outlook 2007.) Unfortunately, I cannot provide the fix for Outlook 2003, though if someone gets it working, I’ll be happy to host the file.

Okay, how do I get it?

Download and install the latest version of AutoHotkey.

Download the Outlook Keys script. By downloading the file, you agree to the legal information included at the end of this page

The zip file has the AHK script and a text file with the macro code for archiving in Outlook.

Save the AHK script someplace in your documents. Double click it to run it. If you want to run the script everytime Windows loads, you’ll have to move a shortcut to the script into the startup folder.

How do I set the macro up for archiving?

The macro code is in the file Outlook Macro Code.txt. You’ll use my code, but follow these instructions to install the macro and set it up so that Outlook doesn’t give you a security warning. (Alternatively, Lifehacker has provided a good writeup on these steps too.)

Pay special attention to how you add a keyboard shortcut to a macro. My AHK script expects that the Outlook macro will have a keyboard shortcut of ALT + . (period). If you give the macro a different shortcut, it won’t work unless you edit my AHK script.

Now perhaps the hardest part is getting the macro to work. Since I don’t know how your folders are setup, you’ll have to change the macro to tell it which folders to use when archiving. Find the following comments in my macro code.

‘set folders to watch

‘set folders to archive to

Currently, if you didn’t modify the code at all, it would work if you had the following folder arrangement in Outlook.

Outlook Folders Hitting ‘a’ on a message(s) in the Inbox would move it into the Personal – Received folder. Hitting ‘a’ on a message(s) in the Business folder would move it into the Business – Received folder.

If there were any other folders in the Inbox that weren’t referenced in the code, then they too would go to Personal – Received, since it’s the default archive folder.

So you’ll need to change the folder paths in the macro to match your needs.

I hope others find it useful too. If anyone finds any bugs, please let me know in the comments.

Future Releases

If future releases or bug fixes are needed, the following feed will announce new releases. http://www.ocellated.com/tag/outlook-keys/feed/

Legal Notice

While the code here has been tested repeatedly under different scenarios and is believed to work properly, by using it you agree to hold its maker harmless from any damages. This code is released WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This code is released under the Creative Commons 3.0 Attribution Non-Commercial Share Alike license. You can share the code and you can change the code if wish, but the license must remain in effect and you must attribute the original source. You cannot use the work for any commercial purpose.

Tagged with: , , ,

26 Responses to “Pimping Microsoft Outlook”

  1. I have an applescript to do this in MS Entourage that I posted last month: http://ericanderson.us/2009/02/27/archiving-a-message-via-keyboard-shortcut-in-microsoft-entourage/

  2. zorglups elucidates:

    I’ll take it and make it work with Outlook 2003.

    Thanks a lot for this. I procrastinate this for years.

  3. Thanks for this great script! To make this work with Outlook 2003, I just changed the Outlook path (on my machine, this consisted of changing “Office13″ to “Office12″). Everything else works beautifully.

  4. Err… I’m guessing you meant “Office12″ to “Office11″, as Office12 is Outlook 2007, and Office11 is Outlook 2003.

  5. Alex verbalizes:


    How would I map the Y to an existing button? (I’m using ClearContext.com and there’s a FileMsg button that I’d love Y to run)

  6. Alex, you can probably assign the button a keyboard shortcut, and then modify the AutoHotkey (AHK) code to send that shortcut to Outlook when you press Y.

    It would look something like this:

    In Outlook, right click on any one of your toolbars and choose Customize. Then, go to the ClearContext button on the toolbar (not on the window that pops up) and right click on it. You’ll see a field labeled “Name:” It might say ClearContext or perhaps Clear&Context. What ever character comes after the ampersand is the shortcut key Outlook will use (in combination with ALT).

    So if you renamed your button C&learContext, then ALT + L would be the outlook shortcut. Clea&rContext would be ALT + R. Try it in Outlook first to make sure it’s working.

    If it’s working, then it’s trivial to edit the AHK file and add something like this:
    y::HandleOutlookKeys(“!l”, “y”) ;calls ClearContext button

    This sends ALT + L to the screen when messages are selected, otherwise it sends Y.

    Good luck.

  7. Alex dares to say:

    HeyA J

    Thanks the reply!

    There’s a typo though……you might want to fix for the next person that cut-and-paste’s

    You have ^l for ALT+L and say ^ = ALT

    but ALT = !

    Took me a bit to figure out but am now happy as larry :)

    Thanks again,
    (PS, feel free to just fix and then delete this comment)

  8. You’re right. Thanks for spotting that. I’ve edited my prior comment for accuracy, but will leave your correction for posterity.

  9. Tony touches upon:

    Is there a way to create a macro that when an email from a certain person comes in, that it will click a url in the email?

  10. I’m sure there is. Good luck writing it. ;)

  11. gmmazza expresses:

    Hi Jay, I just installed the script to move files, I want to know if you have several imap inboxes and I want to move the message to the corresponding folder in each acount:
    acount (top level folder) do [(“top level folder”.inbox to “top level folder”.archive”)
    pe: acount work [(work.inbox) to (work.archive)]
    acount personal [(personal.inbox) to (personal.archive)]

    I found this:

    Set objFolder = objNS.Folders(“Top-level folder”).Folders(“Nested folder”)

    That can work? I don’t have any Idea of programming that’s why I bother you.
    Just get me a direction, I will try to discover what to do.
    Thank you!

  12. this is a great script and definitely help with productivity when you live in outlook all day

  13. @gmmazza, to respond over a month after the question… I don’t know. :) I don’t use IMAP so I’m afraid you’re on your own if IMAP works differently in some way.

  14. I am using Google Apps Sync for Outlook. This Macro doesn’t seem to play well with it. Email simply disappears. Anyone here have a solution?

    I found a link here where someone had the same problem as me, but it seems they haven’t found a fix.


  15. Sorry Alan. You’d really have to ask Google (though of course I doubt they’d give you the time of day…) I’ve used it successfully with POP accounts, IMAP accounts on Gmail, and now Exchange accounts. The only thing I can think of is that Google Apps Sync is somehow “listening” for changes in a non-standard way. This is pure speculation of course.

    One thing that might be interesting is if you could use the Outlook 2010 beta. If Google App Sync is compatible with it, Outlook 2010 has quick actions that you could customize to file messages away to your folder of choice. This would replace the macro part of the archive button. You could still use AHK to call the shortcut of this Outlook action, giving you a single key press to invoke. If that causes problems too, then there’s nothing more I can think of besides ditching Google app sync or getting them to fix it.

  16. I modified the AHK scirpt to make it work with Outlook 2010 on Windows 7. I added a SUPERGRID2 control to the list, and modified some special key mappings, e.g. Reply is CTRL-R not ALT-R. Can’t find a shortcut for the archive macro, though.

    ;Hotkeys for Outlook 2010

    ;As best I can tell, the window text ‘NUIDocumentWindow’ is not present
    ;on any other items except the main window. Also, I look for the phrase
    ; ‘ – Microsoft Outlook’ in the title, which will not appear in the title (unless
    ;a user types this string into the subject of a message or task).
    #IfWinActive – Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow
    ;y::HandleOutlookKeys(“!.”, “y”) ;calls archive macro
    f::HandleOutlookKeys(“^f”, “f”) ;forwards message
    r::HandleOutlookKeys(“^r”, “r”) ;replies to message
    a::HandleOutlookKeys(“^+r”, “a”) ;reply all
    v::HandleOutlookKeys(“^+v”, “v”) ;Move message box
    +u::HandleOutlookKeys(“^u”, “+u”) ;marks messages as unread
    +i::HandleOutlookKeys(“^q”, “+i”) ;marks messages as read (^q is read/unread toggle)
    j::HandleOutlookKeys(“{Down}”, “j”) ;move down in list
    +j::HandleOutlookKeys(“{Down}{Enter}”, “+j”) ;move down and select next item
    k::HandleOutlookKeys(“{Up}”, “k”) ;move up
    +k::HandleOutlookKeys(“{Up}{Enter}”, “+k”) ;move up and select next item
    o::HandleOutlookKeys(“^o”, “o”) ;open message
    s::HandleOutlookKeys(“{Insert}”, “s”) ;toggle flag (star)
    c::HandleOutlookKeys(“^n”, “c”) ;new message
    /::HandleOutlookKeys(“^e”, “/”) ;focus search box
    .::HandleOutlookKeys(“+{F10}”, “.”) ;Display context menu

    ;Passes Outlook a special key combination for custom keystrokes or normal key value, depending on context
    HandleOutlookKeys( specialKey, normalKey ) {
    ;Activates key only on main outlook window, not messages, tasks, contacts, etc.
    IfWinActive, – Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, ,

    ;Find out which control in Outlook has focus
    ControlGetFocus, currentCtrl
    ;MsgBox, Control with focus = %currentCtrl%

    ;set list of controls that should respond to specialKey. Controls are the list of emails and the main (and minor) controls of the reading pane, including controls when viewing certain attachments.
    ;Currently I handle archiving when viewing attachments of Word, Excel, Powerpoint, Text, jpgs, pdfs
    ;The control ‘RichEdit20WPT1′ (email subject line) is used extensively for inline editing. Thus it had to be removed. If an email’s subject has focus, it won’t archive…
    ctrlList = Acrobat Preview Window1, AfxWndW5, AfxWndW6, EXCEL71, MsoCommandBar1, OlkPicturePreviewer1, paneClassDC1, RichEdit20WPT2, RichEdit20WPT4, RichEdit20WPT5, RICHEDIT50W1, SUPERGRID1, SUPERGRID2, _WwG1

    if currentCtrl in %ctrlList%
    Send %specialKey%
    ;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.)
    } else {
    Send %normalKey%

    ;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc.
    } else {
    Send %normalKey%

  17. Thanks Peter. I’ll get around to testing and updating this code for Outlook 2010 soon enough. Just haven’t had the time and am not yet running 2010 as my main environment.

    Also, I added spaces between elements of the ctrlList variable above (so that it would wrap properly). People might need to remove them if using the code.

  18. I have also put together a modified version of the code for Outlook 2010, adding the SUPERGRID2 control to the list. However, I took a different approach than Peter and was able to keep the “archiving” portion working. Instead of using the macro code, I made a Quick Step that moved the current message to the folder of my choice and marked it read. It was a lot easier to set up. I only then had to change the autohotkey script to run CTRL-SHIFT-1 to send the selected messages to the archive folder.

  19. Drew pontificates:

    Moderator: Sorry, didn’t intend to paste all that code, just a snippet surrounded by code tags!

    By the way, thanks for the code, it makes my email management process a breeze!

  20. Can I ask about something specific that is a problem for me?

    My company has obtained an email archiving system that replaces the archive functionality in Outlook 2003 client and beyond (the standard Archive menu item shows as “Disabled by your system administrator” in the File menu for instance).

    This new archiving system will archive all items older than 90 days and put them into a folder which is actually remote on the archiving server. This folder is seen under my mailbox root and is called EV. In fact there are a number of sub-folders under this EV folder that pertain to a number of years that the contents will be retained – yes, this system is a document retention system primarily. These sub folders are named like 001 Year or 003 years or 010 years etc.

    My beef is that I get so much email that my email quota is exceeded in about three weeks so I want to be able to archive all items older than say 21 days into a folder of the same name which will reside under one of the sub folders I mentioned above. In this case, I want to use the “010 Years” sub folder to archive everything to.

    So the logic would be:

    Search through all emails in all sub-folders of the mailbox (except the EV folder).
    If an email was received 21 days or more ago, move the email to a folder of the same name beneath the Mailbox->EV folder while respecting any folder hierarchy.

    i.e. if an email received 22 days ago is found in he folder Mailbox->Finance->Monthly Stuff then it should be moved to exist in the folder Mailbox_>EV->010 Years->Finance->Monthly Stuff .

    Do this until all folders have been looked into and all messages meeting the age criteria have been located and moved.

    Has anyone got this functionality they can offer?



  21. I cant seem to get it working for outlook 2010 can someone help?

  22. It’s still working fine for me in Outlook 2010 Chris. I’m not sure what the problem is, but I’d carefully check your code. Especially make sure the names of the folders you’re trying to archive to match exactly or else it won’t work.

  23. For MS.Outlook 2010, do you require the macro? IT have disabled macros…

  24. nvrmind. I just need to read better. Sorry (please delete both comments?)

  25. FYI for 2010 users, if you have issues with Object Not Found, you may need to change the ArchiveFolder string. This script assumes that your Archive folder is in the same tree as your Inbox, but if you use a different folder, it breaks.

    Not sure if that made sense, but here’s what I ended up having to change it to:
    Set ArchiveFolder = Application.GetNamespace(“MAPI”).Folders(“Archives”).Folders(“Inbox”)

    Sorry – i’m not a dev, so not very good at the lingo :-)

  26. Doh – RTFM. NVM :-)

This entry was posted on Wednesday, March 18th, 2009 at 11:57 am and is filed under Technology. You can follow any comments to this entry through this RSS feed. Both comments and pings are currently closed.