BeforeTranslate Event
Description
Occurs when a shortcut key binding/accelerator is used.
Syntax
Public Event BeforeTranslate( _
ByVal Command As Long, _
ByRef Cancel As Variant _
)
Parameters
- Command: The command ID associated with the accelerator that was just used.
- Cancel: [out] Set to True to cancel the shortcut from being executed.
Remarks
The BeforeTranslate event occurs when a user executes a key binding/shortcut that was added to a command bars item using the Add method or added from the KeyboardPage of the command bars customization dialog. BeforeTranslate occurs after the user presses the key binding on the keyboard but before it is actually executed, 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_BeforeTranslate(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.