Add Method (KeyBindings Collection) Example
This example adds the CTRL+ALT+W key combination to the FileClose command. The keyboard customization is saved in the Normal template.
CustomizationContext = NormalTemplate
KeyBindings.Add _
KeyCategory:=wdKeyCategoryCommand, _
Command:="FileClose", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyW)
This example adds the ALT+F4 key combination to the Arial font and then displays the number of items in the KeyBindings collection. The example then clears the ALT+F4 key combination (returned it to its default setting) and redisplays the number of items in the KeyBindings collection.
CustomizationContext = ActiveDocument.AttachedTemplate
Set myKey = KeyBindings.Add(KeyCategory:=wdKeyCategoryFont, _
Command:="Arial", KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyF4))
MsgBox KeyBindings.Count & " keys in KeyBindings collection"
myKey.Clear
MsgBox KeyBindings.Count & " keys in KeyBindings collection"
This example adds the CTRL+ALT+S key combination to the Font command with 8 points specified for the font size.
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCategory:=wdKeyCategoryCommand, _
Command:="FontSize", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyS), _
CommandParameter:="8"
This example adds the CTRL+ALT+H key combination to the Heading 1 style in the active document.
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCategory:=wdKeyCategoryStyle, _
Command:="Heading 1", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyH)
This example adds the CTRL+ALT+O key combination to the AutoText entry named "Hello."
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCategory:=wdKeyCategoryAutoText, _
Command:="Hello", _
KeyCode:=BuildKeyCode(wdKeyControl, wdKeyAlt, wdKeyO)