Share via

Key Assignments

Anonymous
2016-11-29T06:09:03+00:00

Is there any way to automate or otherwise automatically assign macros/commands/styles to specific keys?

I regularly use about 30 such assignments, and when "repair" is needed, the assignments are commonly erased. Setting each assignment individually is a tedious process.

Any suggestions would be most welcome.

John

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2016-11-29T12:57:51+00:00

You can write a macro that contains KeyBindings.Add statements, one for each of the shortcuts you want. Each statement associates a shortcut key combination with a built-in command, a macro, or another kind of action.

The following example is reproduced from https://gist.github.com/pwgerman/49a8f1a9a69c6b0d86eb. You'll have to replace the shortcuts (in the BuildKeyCode function calls) and the commands with your items.

Sub EmacsCustomKeybind()
'
' Emacs1 Macro
' Assigns emacs and other useful keybindings to Keyboard Customization.
'
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyB, wdKeyOption, wdKeyControl), _
        KeyCategory:=wdKeyCategoryCommand, Command:="WordLeft"
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyB, wdKeyShift, wdKeyOption, _
        wdKeyControl), KeyCategory:=wdKeyCategoryCommand, Command:= _
        "WordLeftExtend"
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyP, wdKeyShift, wdKeyControl), _
        KeyCategory:=wdKeyCategoryCommand, Command:="LineUpExtend"
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyN, wdKeyShift, wdKeyControl), _
        KeyCategory:=wdKeyCategoryCommand, Command:="LineDownExtend"
    CustomKeybind_DeleteChar
End Sub

Sub DeleteChar()
'
' EditBack1 Macro
' Forward delete one char to the right
'
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeBackspace
End Sub
Sub CustomKeybind_DeleteChar()
'
' Add_delete_macro_shortcut Macro
'
'
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyD, wdKeyControl), KeyCategory:= _
        wdKeyCategoryMacro, Command:="DeleteChar"
End Sub

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Suzanne S Barnhill 278.1K Reputation points MVP Volunteer Moderator
    2016-11-29T18:42:23+00:00

    Instead of saving these key assignments in your Normal template, you might save them in an add-in template (in Word's Startup folder), where would be less susceptible to being wiped.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-11-29T17:20:08+00:00

    Amazingly quick and helpful response. Many thanks! John

    Was this answer helpful?

    0 comments No comments