Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bind a macro to the Hash key (Office 2000 / 2003)

    I'm using KeyBindings.Add to assign macros to various keys, but I can't add one to the Hash key. wdKey# doesn't seem to exist any more. Is there any way of donig this?, or should I just use another key!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 2003)

    There is no separate constant for the hash key. On my keyboard, the hash key is Shift+3, so I must use BuildKeyCode(wdKey3, wdKeyShift) to specify it. For example:

    KeyBindings.Add wdKeyCategoryMacro, "MyMacro", BuildKeyCode(wdKey3, wdKeyShift)

  3. #3
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    I should of said that I am using a UK English keyboard. The # (hash) key on it is next to the Enter key - shifted it gives a ~ (tilde). As far as I can remember wdKey# existed in Word 97 and maybe whatever came next. It must of worked once 'cause I've used it!

    Dennis.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    I don't think that vbKey# or wdKey# would be valid as a name in VBA.

    I'm afraid I can't find any relevant information. Perhaps someone else with a UK keyboard knows how to do this.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    Dennis,
    Apparently, the wdKey constants are not always reliable (as different keyboards can return different codes for the same character) so I wouldn't use them other than for the simple letters/numbers and I think the function keys are safe. You need to use an API call to be sure. Based on an article in MSDN, this should work for you:
    <pre>Public Declare Function VkKeyScan Lib "user32" _
    Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer

    Sub BindHash()
    KeyBindings.Add _
    KeyCode:=VkKeyScan(Asc("#")), _
    KeyCategory:=wdKeyCategoryMacro, _
    Command:="macronamehere"
    End Sub
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Lounger
    Join Date
    Dec 2002
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    Thanks for that. Given the info re the wdKey values, I think I'll re-write the template based on your suggestion so that it should always work!

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    I'm curious. Why did you use "wdKeyCategoryMacro" (value 2) rather than "wdKeyCategoryCommand" (value 1)?

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Bind a macro to the Hash key (Office 2000 / 20

    Because I was binding it to a macro, not a built-in command. I suspect it would work either way but it's clearer when you come to review, I think, if you differentiate between the two.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •