OL2000: How to Assign a Macro to a Shortcut Key

Article translations Article translations
Article ID: 252427 - View products that this article applies to.
Expand all | Collapse all

On This Page

Summary

This article describes how you can assign an Outlook Visual Basic for Applications macro to a shortcut key.

More information

You can create Visual Basic for Applications macros that use the Outlook object model to perform certain tasks. You can assign the macro to a shortcut key to easily run the macro at any time.

It is important to keep in mind that unlike other Microsoft Office programs, Outlook does not directly contain a feature that lets you customize shortcut keys. However, you can assign shortcut keys to Outlook menus and toolbars. Either of the following two approaches may satisfy your needs.

Use the Shortcut Keys for Menus

You can customize the toolbar or a menu by adding a macro.

For additional information about how to add a macro to a toolbar or menu, click the article number below to view the article in the Microsoft Knowledge Base:
252426 OL2000: How to Assign a Macro to a Toolbar Button
When you add the macro to the menu, be sure to precede one of the letters in the name with an ampersand (&). This makes that letter a shortcut key and the letter appears underlined on the menu. You can run the macro by using two separate key combinations, the first to select the menu, and the second to run the macro on the menu.

For example, assume that you create a macro to do a search and replace operation on your contacts. You name the macro "UpdateContacts," add the macro to the Tools menu, and specify that the name of the menu command is "Upd&ate Contacts." Note the ampersand precedes the letter "a" in the name that will appear on the menu. To run this macro using the keyboard, use two key combinations. First, press ALT+T to open the Tools menu, and then press A to run the macro.

Use the Shortcut Keys for Toolbar Buttons

The only way to use a single shortcut key is to use the above approach, but add the command or button to a toolbar, instead of a menu. This method can have some adverse side effects and must be implemented carefully and with the expectation that you may not be successful.

The following issues should be taken into account:
  • For the shortcut key to work, the toolbar button must be set to display text that includes the shortcut key assignment. You cannot use a toolbar button that displays an icon.
  • In general, you must ensure that the shortcut key you select does not conflict with a shortcut key being used by Outlook. Custom buttons can conflict with existing menus or toolbar buttons. When this happens, neither the default command nor your custom macro will run. For example, if you add a toolbar button with the name of "Upd&ate Contacts", when you press ALT+A neither the Actions menu, nor the custom toolbar button works.
  • Because the Outlook menus and toolbars are dynamic, it may be difficult to determine if a custom shortcut key will work in all scenarios. For example, if you add a toolbar button named "Update &Contacts", this toolbar button works while you are in a Contacts folder. However, if you switch to the Inbox, the shortcut key conflicts with the Send/Receive button on the toolbar. If you need a shortcut key to be available at all times, use "trial-and-error" testing under various scenarios.
  • The menus, toolbars, and shortcut keys used by Outlook are subject to change, so it is possible that your shortcut key selections may conflict, or otherwise not work in future versions of Outlook.
NOTE: Since Visual Basic for Applications is considered "application-level" code, add the toolbar button to the Standard toolbar and not the toolbars on items.

References

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:
146636 OL2000: Questions About Custom Forms and Outlook Solutions

Properties

Article ID: 252427 - Last Review: June 19, 2014 - Revision: 4.0
Applies to
  • Microsoft Outlook 2000 Standard Edition
Keywords: 
kbhowto KB252427

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com