KeyBinding.Rebind Method

Word Developer Reference

Changes the command assigned to the specified key binding.

Syntax

expression.Rebind(KeyCategory, Command, CommandParameter)

expression   Required. A variable that represents a KeyBinding object.

Parameters

Name Required/Optional Data Type Description
KeyCategory Required WdKeyCategory The key category of the specified key binding.
Command Required String The name of the specified command.
CommandParameter Optional Variant Additional text, if any, required for the command specified by Command. For information about values for this argument, see the Add method.

Example

This example reassigns the CTRL+SHIFT+S key binding to the FileSaveAs command.

Visual Basic for Applications
  Dim kbTemp As KeyBinding

CustomizationContext = NormalTemplate Set kbTemp = _ FindKey(BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyS)) kbTemp.Rebind KeyCategory:=wdKeyCategoryCommand, _ Command:="FileSaveAs"

This example rebinds all keys assigned to the macro named "Macro1" to the macro named "ReportMacro."

Visual Basic for Applications
  Dim kbLoop As KeyBinding

CustomizationContext = ActiveDocument.AttachedTemplate For Each kbLoop In _ KeysBoundTo(KeyCategory:=wdKeyCategoryMacro, _ Command:="Macro1") kbLoop.Rebind KeyCategory:=wdKeyCategoryMacro, _ Command:="ReportMacro" Next kbLoop

See Also