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

Posted on 2009-02-11
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?
Question by:PioneerSolutions
    LVL 22

    Expert Comment

    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.

    LVL 4

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
    Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
    This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now