views:

2319

answers:

2

How can I assign a keyboard shortcut to a VBA macro in Outlook 2007?

I know how to create a tool for the macro and put it in a menu with an underscore shortcut. This solution requires me to use a shortcut of ALT-{menu key}-{tool key}. What if I want to assign it to ALT-F12 or something like that?

The Visual Basic Editor is assigned to the keyboard shortcut ALT-F11 in Outlook 2007. I want to assign a keyboard shortcut like that to a macro, or if necessary a macro on a tool in either a menu or a toolbar.

+3  A: 

Since Outlook doesn't have the OnKey event, the easiest way is to assign a toolbar button to the macro and put an ampersand in its name somewhere. This only works if your shortcut letter doesn't conflict with an existing shortcut.

You may also have luck with setting a global hotkey, but it's usually more pain then it's worth:

http://www.mvps.org/vbvision/_samples/HotKey_Demo.zip

rpetrich
RE: the comment above about "This only works if your shortcut letter doesn't conflict with an existing shortcut."Not entirely true, i'm not sure if they removed the restriction or if there ever was one, but you can add a shortcut to a command even if the same shortcut already exists for a builtin command on the same menu. The user just needs to press the shortcut key a second time to get to the alternative command, if they don't it will go to the first one. Microsoft even use this arrangement for one or two commands.
Anonymous Type
Very good point; I hadn't realized that.
rpetrich
+1  A: 

The article Do-It-Yourself IntelliSense from MSDN provides excellent information about key bindings in VBA.

guillermooo