返回一个 KeyBinding 对象,该对象代表了指定的自定义组合键。如果该组合键不存在,则本方法返回 Nothing。
expression.Key(KeyCode, KeyCode2)
expression 必需。该表达式返回一个 KeyBindings 或 KeysBoundTo 对象。
KeyCode Long 类型,必需。用 WdKey 常量指定的一个键。
KeyCode2 Variant 类型,可选。用 WdKey 常量指定的第二个键。
可用 BuildKeyCode 方法创建 KeyCode 或 KeyCode2 参数。
本示例将 Alt+F4 指定给 Arial 字体,然后显示 KeyBindings 集合中的项数。接着清除该组合键(将它恢复到默认设置),并重新显示 KeyBindings 集合中的项数。
CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyF4), _
KeyCategory:=wdKeyCategoryFont, Command:="Arial"
MsgBox KeyBindings.Count & " keys in KeyBindings collection"
KeyBindings.Key(KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyF4)).Clear
MsgBox KeyBindings.Count & " keys in KeyBindings collection"
本示例在活动文档中将 Ctrl+Shift+U 指定给宏“Macro1”。本示例使用 Key 属性返回一个 KeyBinding 对象,这样 Word 可以查找并显示命令名称。
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyU), KeyCategory:=wdKeyCategoryMacro, _
Command:="Macro1"
MsgBox KeyBindings.Key(BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyU)).Command
本示例判定 Ctrl+Shift+A 是否为 KeyBindings 集合的一部分。
Dim kbTemp As KeyBinding
CustomizationContext = NormalTemplate
Set kbTemp = KeyBindings.Key(BuildKeyCode(wdKeyControl, _
wdKeyShift,wdKeyA))
If (kbTemp Is Nothing) Then MsgBox _
"Key is not in the KeyBindings collection"