Word 2007 key bindings - VBA

Discussion in 'Word VBA Beginners' started by olley, Sep 4, 2007.

  1. olley

    olley Guest


    I have problem with KeyBindings in Word 2007. I bind diferrent funcitons to
    Alt+8 and Alt+* (on numeric pad). It works just fine in Word 2003. However in
    Word 2007 it always calls Alt+8 bound function. Seems that Word 2007 cannot
    differentiate between wdKey8 and wdKeyNumericMultiply, even though
    BuildKeyCode() returns different values for those combinations.

    Does anyone know if this is a bug or a feature in new Word 2007? Is there a
    workaround for this?


    Here is the code sample. In Word 2007 it always call "EghtPressed"

    KeyBindings.Add KeyCode:=BuildKeyCode(

    KeyBindings.Add KeyCode:=BuildKeyCode(
    olley, Sep 4, 2007
    1. Advertisements

  2. olley

    Klaus Linke Guest

    Klaus Linke, Sep 5, 2007
    1. Advertisements

  3. olley

    olley Guest

    Hi Klaus,

    Thanks for your response.
    Unfortunately it didn't do the trick ;) This article (that particular part
    you pointed to) explains how to get correct scancode for any keyboard using
    VkKeyScan() Win API function. However, in MSDN for this function they say:
    "Translations for the numeric keypad (VK_NUMPAD0 through VK_DIVIDE) are
    ignored." And indeed it doesn't build scancode for * on numeric keyboard.

    The problem here is not getting correct scancode, but rather is how Word
    2007 binds keys on numeric keypad (even for well-known scan codes). To me it
    seems that Word 2007 cannot handle numeric keypad key bindings correctly.

    Thank you,
    olley, Sep 7, 2007
  4. olley

    Klaus Linke Guest

    Yes, seems like it's reserved or something. I can assign
    wdKeyNumericMultiply alone, but not with Alt.
    Maybe it has something to do with ribbon navigation (using Alt, and then
    moving through the tabs and chunks with the direction keys)?

    I can assign Alt+wdKeyNumeric8, though it only works if NumLock is turned

    Klaus Linke, Sep 8, 2007
  5. olley

    olley Guest

    I ended up doing following. I bind "8" key with Alt using regular call:
    KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKey8),

    And then in Handler8() funciton I check if wdKeyNumericMultiply is still
    pressed. For that I use Win32 API GetKeyState() function. If it is pressed
    then I call my regular handler for Alt+<Num*> keystroke. There is a potential
    danger that by the time I call GetKeyState() the user would already release
    Num*. But it seems to be working for me now. Oh, and I do it only if the
    current Word version is 2007.

    Klaus, thanks for the idea of using Win32 API directly. I would not get to
    it without your hint about different API call ;)
    olley, Sep 13, 2007
  6. olley

    Klaus Linke Guest

    Thanks, and good to hear you got something working!

    Klaus Linke, Sep 15, 2007
  7. Use this instead

    BuildKeyCode(wdKeyControl, wdKeyNumeric8)

    And if your are not using the numeric keypad, use wdKey8

    Hope it may help
    Maurice Pelchat, Aug 31, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.