Keycode constants for a vertical bar or reverse slash

Posted on 2009-12-23
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
    LVL 14

    Accepted Solution

    It's ASCII code 124. Can't you just use "|" or Chr(124) instead of the constant?

    Author Closing Comment

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    754 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

    14 Experts available now in Live!

    Get 1:1 Help Now