Skip to content

KeyBinding Object

Description

Represents a key binding object.

For a list of all members defined in this module, see KeyBinding Members.

Example

The following example demonstrates how to find a shortcut by CommandBar Control ID and how to iterate through all shortcuts.

Dim KeyBindings As KeyBindings

Set KeyBindings = CommandBars.KeyBindings

KeyBindings.AddShortcut ID_FILE_NEW, "Ctrl+N"
KeyBindings.AddShortcut ID_FILE_OPEN, "Ctrl+O"
KeyBindings.AddShortcut ID_FILE_SAVE, "Ctrl+S"
KeyBindings.AddShortcut ID_EDIT_CUT, "Ctrl+X"
KeyBindings.AddShortcut ID_EDIT_COPY, "Ctrl+C"

Dim keyShortcut As KeyBinding

' Finds a shortcut by commandbar ID
keyShortcut = KeyBindings.FindShortcut(ID_FILE_NEW)

If Not keyShortcut Is Nothing Then
    Debug.Print "The commandbar control that uses this shortcut has an ID of " & keyShortcut.Command
    Debug.Print "The shortcut text for commandbar control with ID of " & keyShortcut.Command & " is " & keyShortcut.ShortcutText
End If

For Each keyShortcut In KeyBindings
    Debug.Print "The commandbar control that uses this shortcut has an ID of " & keyShortcut.Command
    Debug.Print "The shortcut text for commandbar control with ID of " & keyShortcut.Command & " is " & keyShortcut.ShortcutText
Next

See Also

KeyBinding Members


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.