We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Word 2007: How do I programmatically assign a shortcut to a vba procedure

Medium Priority
Last Modified: 2013-11-25
I have a Hello World procedure stored in a particular word 2007 (macro enabled) document that I use a lot:
Sub HelloWorld()
MsgBox "Hello World"
End Sub

How can I programmatically (using vba) assign a shortcut of:
Alt + q or Alt + Shift + q
to this procedure?
Thank you!

p.s. if not possible, any alternatives?
Watch Question


Go to the Office button and select Word Options - Customize. At the bottom of that screen is Keyboard Options. Select Customize. In the categories box select Macros. Click in the Press new shortcut key box and then press the hotkeys you want, i.e. ctrl+shift+8.

Flyster clearly didn't understand the question.

Attached is the VBA code for assigning the key combination [Alt + Q] to the procedure named HelloWorld.

Note: The HelloWorld procedure must be stored in the document, not in a module.
CustomizationContext = ThisDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyW), _
KeyCategory:=wdKeyCategoryMacro, Command:="HelloWorld"

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.