Word 2007 key bindings - VBA

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

  1. olley

    olley Guest

    Hi,

    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?

    Thanks!

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

    KeyBindings.Add KeyCode:=BuildKeyCode(
    arg1:=wdKeyAlt,
    Arg2:=wdKey8),
    KeyCategory:=wdKeyCategoryCommand,
    Command:="EightPressed"

    KeyBindings.Add KeyCode:=BuildKeyCode(
    arg1:=wdKeyAlt,
    Arg2:=wdKeyNumericMultiply),
    KeyCategory:=wdKeyCategoryCommand,
    Command:="StarPressed"
     
    olley, Sep 4, 2007
    #1
    1. Advertisements

  2. olley

    Klaus Linke Guest

    Haven't checked it out in Word 2007, but using the Windows API should do the
    trick.
    See Romke Soldaat's article
    http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
    (scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
    Can't Do")

    Regards,
    Klaus


    "olley" wrote:
    > Hi,
    >
    > 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?
    >
    > Thanks!
    >
    > Here is the code sample. In Word 2007 it always call "EghtPressed"
    >
    > KeyBindings.Add KeyCode:=BuildKeyCode(
    > arg1:=wdKeyAlt,
    > Arg2:=wdKey8),
    > KeyCategory:=wdKeyCategoryCommand,
    > Command:="EightPressed"
    >
    > KeyBindings.Add KeyCode:=BuildKeyCode(
    > arg1:=wdKeyAlt,
    > Arg2:=wdKeyNumericMultiply),
    > KeyCategory:=wdKeyCategoryCommand,
    > Command:="StarPressed"
    >
    >
     
    Klaus Linke, Sep 5, 2007
    #2
    1. Advertisements

  3. olley

    olley Guest

    Hi Klaus,

    Thanks for your response.

    > Haven't checked it out in Word 2007, but using the Windows API should do the
    > trick.
    > See Romke Soldaat's article
    > http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
    > (scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
    > Can't Do")


    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
    #3
  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
    on.

    Regards,
    Klaus


    "olley" <> schrieb im Newsbeitrag
    news:D...
    > Hi Klaus,
    >
    > Thanks for your response.
    >
    >> Haven't checked it out in Word 2007, but using the Windows API should do
    >> the
    >> trick.
    >> See Romke Soldaat's article
    >> http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
    >> (scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
    >> Can't Do")

    >
    > 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,
     
    Klaus Linke, Sep 8, 2007
    #4
  5. olley

    olley Guest

    "Klaus Linke" wrote:

    > 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 ended up doing following. I bind "8" key with Alt using regular call:
    KeyBindings.Add
    KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKey8),
    KeyCategory:=wdKeyCategoryCommand,
    Command:="Handler8"

    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
    #5
  6. olley

    Klaus Linke Guest

    Thanks, and good to hear you got something working!

    Regards,
    Klaus
     
    Klaus Linke, Sep 15, 2007
    #6
  7. You don't use the proper key indentifier

    Use this instead

    BuildKeyCode(wdKeyControl, wdKeyNumeric8)

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

    Hope it may help

    > On Tuesday, September 04, 2007 4:48 PM olle wrote:


    > Hi,
    >
    > 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?
    >
    > Thanks!
    >
    > Here is the code sample. In Word 2007 it always call "EghtPressed"
    >
    > KeyBindings.Add KeyCode:=BuildKeyCode(
    > arg1:=wdKeyAlt,
    > Arg2:=wdKey8),
    > KeyCategory:=wdKeyCategoryCommand,
    > Command:="EightPressed"
    >
    > KeyBindings.Add KeyCode:=BuildKeyCode(
    > arg1:=wdKeyAlt,
    > Arg2:=wdKeyNumericMultiply),
    > KeyCategory:=wdKeyCategoryCommand,
    > Command:="StarPressed"



    >> On Tuesday, September 04, 2007 8:58 PM Klaus Linke wrote:


    >> Haven't checked it out in Word 2007, but using the Windows API should do the
    >> trick.
    >> See Romke Soldaat's article
    >> http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
    >> (scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
    >> Can't Do")
    >>
    >> Regards,
    >> Klaus
    >>
    >>
    >> "olley" wrote:



    >>> On Friday, September 07, 2007 4:52 PM olle wrote:


    >>> 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,



    >>>> On Saturday, September 08, 2007 2:09 PM Klaus Linke wrote:


    >>>> 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
    >>>> on.
    >>>>
    >>>> Regards,
    >>>> Klaus
    >>>>
    >>>>
    >>>> "olley" <> schrieb im Newsbeitrag
    >>>> news:D...



    >>>>> On Thursday, September 13, 2007 3:02 PM olle wrote:


    >>>>> "Klaus Linke" wrote:
    >>>>>
    >>>>>
    >>>>> I ended up doing following. I bind "8" key with Alt using regular call:
    >>>>> KeyBindings.Add
    >>>>> KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKey8),
    >>>>> KeyCategory:=wdKeyCategoryCommand,
    >>>>> Command:="Handler8"
    >>>>>
    >>>>> 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 ;)



    >>>>>> On Friday, September 14, 2007 8:35 PM Klaus Linke wrote:


    >>>>>> Thanks, and good to hear you got something working!
    >>>>>>
    >>>>>> Regards,
    >>>>>> Klaus



    >>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
    >>>>>> Auto-Generate Code for LINQ to SQL Repository Pattern using T4
    >>>>>> http://www.eggheadcafe.com/tutorial...-linq-to-sql-repository-pattern-using-t4.aspx
     
    Maurice Pelchat, Aug 31, 2010
    #7
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zSplash

    Enter key ends Hanging Indent

    zSplash, Oct 3, 2003, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    106
    zSplash
    Oct 6, 2003
  2. Deloris

    Word Certificate of Authenticity Key

    Deloris, Oct 9, 2003, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    66
    Doug Robbins - Word MVP
    Oct 11, 2003
  3. Brian Stigler

    Toggling the Insert Key

    Brian Stigler, Oct 17, 2003, in forum: Word VBA Beginners
    Replies:
    3
    Views:
    305
    DeeJee
    Oct 17, 2003
  4. Simon

    VBA in Word 97 and Word 2002 / Office XP:

    Simon, Jul 14, 2004, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    76
    Jonathan West
    Jul 14, 2004
  5. harrypiper

    CD key for WORD 2000

    harrypiper, Nov 20, 2004, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    104
    Doug Robbins
    Nov 21, 2004
  6. Glenn

    Word 97 VBA in Word 2003

    Glenn, Apr 21, 2007, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    87
    Glenn
    May 18, 2007
  7. Paul M. Eldridge

    VBA Command to Refresh Excel Charts in Word 2007?

    Paul M. Eldridge, Jun 1, 2008, in forum: Word VBA Beginners
    Replies:
    4
    Views:
    383
    Paul M. Eldridge
    Jun 2, 2008
  8. Ailish
    Replies:
    8
    Views:
    580
    Ailish
    Jul 19, 2009
Loading...