[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Keycode constants for a vertical bar or reverse slash

Posted on 2009-12-23
Medium Priority
Last Modified: 2016-02-11
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.

Question by:JohnRobinAllen
  • 2
LVL 14

Accepted Solution

VBClassicGuy earned 500 total points
ID: 26115826
It's ASCII code 124. Can't you just use "|" or Chr(124) instead of the constant?

Author Closing Comment

ID: 31669633
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.

Author Comment

ID: 40854972
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 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