Skip to content

BeforeAdd Event

Description

Occurs when a shortcut key binding is added to a command using the command bars customization dialog.

Syntax

Public Event BeforeAdd( _
    ByVal fVirt As Long, _
    ByVal Key As Long, _
    ByVal Command As Long, _
    ByRef Cancel As Variant _
)

Parameters

  • fVirt
    Specifies whether the Control, Shift, and Alt keys are used for the key binding.

  • Key
    The ASCII key for the key binding.

  • Command
    The command ID which will be invoked when the accelerator is used.

  • Cancel [out]
    Set to True to cancel the shortcut from being added.

Remarks

The BeforeAdd event occurs when a user adds a key binding/shortcut to a command using the KeyboardPage of the command bars customization dialog. BeforeAdd occurs after the user adds the key binding but before it is actually assigned to the command, giving you the opportunity to modify or cancel the operation.

Example

Shortcut Key Constants (Visual Basic)

Public Const FSHIFT = 4  
Public Const FCONTROL = 8  
Public Const FALT = 16  

Public Const VK_BACK = &H8  
Public Const VK_TAB = &H9  
Public Const VK_ESCAPE = &H1B  
Public Const VK_SPACE = &H20  
Public Const VK_PRIOR = &H21  
Public Const VK_NEXT = &H22  
Public Const VK_END = &H23  
Public Const VK_HOME = &H24  
Public Const VK_LEFT = &H25  
Public Const VK_UP = &H26  
Public Const VK_RIGHT = &H27  
Public Const VK_DOWN = &H28  
Public Const VK_INSERT = &H2D  
Public Const VK_DELETE = &H2E  
Public Const VK_MULTIPLY = &H6A  
Public Const VK_ADD = &H6B  
Public Const VK_SEPARATOR = &H6C  
Public Const VK_SUBTRACT = &H6D  
Public Const VK_DECIMAL = &H6E  
Public Const VK_DIVIDE = &H6F  
Public Const VK_F1 = &H70  
Public Const VK_F2 = &H71  
Public Const VK_F3 = &H72  
Public Const VK_F4 = &H73  
Public Const VK_F5 = &H74  
Public Const VK_F6 = &H75  
Public Const VK_F7 = &H76  
Public Const VK_F8 = &H77  
Public Const VK_F9 = &H78  

' Sample usage  
Private Sub KeyBindings_BeforeAdd(ByVal fVirt As Long, ByVal key As Long, ByVal Command As Long, Cancel As Variant)  
    Dim Action As CommandBarAction  
    Set Action = CommandBars.Actions(Command)  
    If Not Action Is Nothing Then  
        Debug.Print "KeyBinding: " & Action.Caption  
    End If  
End Sub

See Also


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