Link to home
Start Free TrialLog in
Avatar of JohnRobinAllen
JohnRobinAllenFlag for Canada

asked on

Keycode constants for a vertical bar or reverse slash

A search for "keyboard constants" in MS Word help or a Google search brings up a table of Keycode constants. Neither location shows a keycode for the "\" (reverse slash) or the "|" (vertical bar, which is a shift + the reverse slash).

I am using the following command in VBA to program a shortcut to run a subroutine:

      KeyBindings.Add KeyCategory:=wdKeyCategoryMacro, _
        Command:="MontTableToAutoCorrect", _
        KeyCode:=BuildKeyCode(wdKeyShift, wdKeyAlt, wdKeyM)

That programs a Shift+Alt+M to run the "MontTableToAutoCorrect" subroutine. I would like to change it to a Shift+Alt+|, which would mean I should change wdKeyM. I just cannot see what the keyboard constant would be for a vertical bar.

Thanks!
    --j.r.a.
ASKER CERTIFIED SOLUTION
Avatar of VBClassicGuy
VBClassicGuy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnRobinAllen

ASKER

The solution is so simple, I am ashamed I did not think of it. Constants are just numbers with a fancy name. If there is no constant for a given key, or for anything else, one can just use the number itself.
     
The solution is so simple, it makes me feel justifiably stupid. I am grateful for the help.
   
     Thanks!
I realize that this question is closed, but despite my premature enthusiasm for the solution I had accepted six years ago,
        that solution above will not work.

In the interests of resolving the question for others, there is a solution. To code for a vertical bar, use two codes, as in:

     BuildKeyCode(wdKeyShift, wdKeyBackSlash, wdKeyControl, wdKeyAlt)

where "wdKeyShift, wdKeyBlackSlash" effectively indicate the otherwise missing constant for a vertical bar. To type a vertical bar on a keyboard, you have to type Shift + the backslash.
     --John Robin Allen, Priddis, Alberta