Click Event

Description

Occurs when the OnAction property of a corresponding command bar control is set.

Syntax

Sub object_Click (ByVal ctrl As Object, ByRef handled As Boolean, ByRef canceldefault As úBoolean)

The Click event syntax has these named arguments:

Part

Description

ctrl

Required; Object. Specifies the object that is the source of the Click event.

handled

Required; Boolean. If True, other add-ins should handle the event. If False, the action of the command bar item has not been handled.

canceldefault

Required; Boolean. If True, default behavior is performed unless canceled by a downstream add-in. If False, default behavior is not performed unless restored by a downstream add-in.


Remarks

The Click event is specific to the CommandBarEvents object. Use a variable declared using the WithEvents keyword to receive the Click event for a CommandBar control. This variable should be set to the return value of the CommandBarEvents property of the Events object. The CommandBarEvents property takes the CommandBar control as an argument. When the CommandBar control is clicked (for the variable you declared using the WithEvents keyword), the code is executed.

Example

The following example illustrates how you can set up code for a Click event procedure using WithEvents and Set. Note that the object reference ce is used in place of the menu name Tools in the name of the Click event.

Private WithEvents ce As CommandBarEvents

Sub Test()
    Dim c As CommandBarControl
    Set c = Application.VBE.CommandBars("Tools").Controls(1)
    Set ce = Application.VBE.Events.CommandBarEvents(c)
End Sub

Private Sub ce_Click(ByVal CommandBarControl As Object, Handled As Boolean, CancelDefault As Boolean)
    ' Put event-handling code here
End Sub