Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA keyboard shortcut & menu button 1

Status
Not open for further replies.

sera

Technical User
Jun 29, 2000
360
US
Does anyone know how to assign a keyboard shortcut to a macro in word VBA. This needs to be done programmatically because "Document Routing" removes the key-binding and menu item for a macro. So I need to make the key-bind on AutoOpen(). The method through the menus doesn't persist.

I also would like this for a menu button but i'd take just the key bind!

Thanks...

Sera
 
Here's a re-typing of something done ages ago (not tested in ages, but they haven't complained)

This is supposed to get some action on the F2 key.

[tt]CustomizationContext = NormalTemplate
FindKey(KeyCode:=wdKeyF2).Clear
KeyBindings.Add KeyCode:=wdKeyF2, KeyCategory:=wdKeyCategoryMacro, Command:= "NameOfSub"[/tt]

To use shift/ctrl/alt ... I think you can do something like

[tt]FindKey(KeyCode:=BuildKeyCode(wdKeyShift, wdKeyF8)).Clear
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyShift, wdKeyF8), KeyCategory:=wdKeyCategoryMacro, Command:= "NameOfNotherSub"[/tt]


Here's a couple of threads on menu stuff thread707-1001276, thread707-739271. Hopefully this can be a starting point?

Roy-Vidar
 
thanks that works great....

i actually found the answer in the F1 bastard help right before you sent this... but it does work!

thanks for the fast response.

Sera
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top