Disable 方法

       

如果已将一个组合键分配给某一命令,则本方法将删除这个组合键。应用本方法后,组合键将不再起作用。本方法相当于在“工具”菜单的“自定义键盘”对话框中单击“删除”按钮。

注意   对 KeyBinding 对象使用 Clear 方法,可以为一个内置命令重新设置默认的按键分配方案。将 KeyBinding 对象添至其他位置时,不必删除或者重新绑定该对象。

expression.Disable

expression   必需。该表达式返回一个 KeyBinding 对象。

示例

本示例删除 Ctrl+Shift+B 的按键分配方案。默认情况下,此组合键分配给 Bold 命令。

CustomizationContext = NormalTemplate
FindKey(BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyB)).Disable

本示例将 Ctrl+Shift+O 指定给 Organizer 命令。然后本示例用 Disable 方法删除 Ctrl+Shift+O 的指定方案,并且显示一条消息。

CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyO, _
    wdKeyControl, wdKeyShift), _
    KeyCategory:=wdKeyCategoryCommand, Command:="Organizer"
With FindKey(BuildKeyCode(wdKeyO, wdKeyControl, wdKeyShift))
    MsgBox .Command & " is assigned to CTRL+Shift+O"
    .Disable
    If .Command = "" Then MsgBox _
        "Nothing is assigned to CTRL+Shift+O"
End With

本示例删除名为“Macro1”的共用宏的所有按键分配方案。

Dim kbLoop As KeyBinding

CustomizationContext = NormalTemplate
For Each kbLoop In KeysBoundTo _
        (KeyCategory:=wdKeyCategoryMacro, Command:="Macro1")
    kbLoop.Disable
Next kbLoop