Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 532
Magnus Lindhe Avatar asked Sep 11 '08 16:09

Magnus Lindhe


People also ask

How do I set keyboard shortcuts in VBA?

Run a macro with custom keyboard shortcutOn the Developer tab, in the Code group, click Macros. In the Macro dialog box, click Options. The Macro Options dialog box will appear. In the Shortcut key box, type any uppercase or lowercase letter that you want to use for the shortcut, and then click OK to save the changes.

Can you run a macro using a keyboard shortcut?

You could run your macro by using a shortcut key. Shortcut keys are case sensitive. Select (Tools > Macro > Macros) to display the Macro dialog box. Select the macro that you want to assign a shortcut key to and press the "Options" button.


2 Answers

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

like image 157
rpetrich Avatar answered Oct 06 '22 00:10

rpetrich


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

like image 29
guillermooo Avatar answered Oct 05 '22 23:10

guillermooo