BeforeRightClick Event [Excel 2003 VBA Language Reference]
BeforeRightClick event as it applies to the Worksheet object.
Occurs when a worksheet is right-clicked, before the default right-click action.
Private Subexpression**_BeforeRightClick**(ByVal Target As Range, Cancel As Boolean)
expression A variable which references an object of type Worksheet declared with events in a class module.
Target Required. The cell nearest to the mouse pointer when the right-click occurs.
Cancel Optional. False when the event occurs. If the event procedure sets this argument to True, the default right-click action doesn't occur when the procedure is finished.
BeforeRightClick event as it applies to the Chart object.
Occurs when a chart element is right-clicked, before the default right-click action.
Private Subexpression**_BeforeRightClick**(Cancel As Boolean)
expression A variable which references an object of type Chart declared with events.
Cancel Required. False when the event occurs. If the event procedure sets this argument to True, the default right-click action isn't performed when the procedure is finished.
Remarks
Like other worksheet events, this event doesn't occur if you right-click while the pointer is on a shape or a command bar (a toolbar or menu bar).
Example
As it applies to the Worksheet object.
This example adds a new menu item to the shortcut menu for cells B1:B10.
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Dim icbc As Object
For Each icbc In Application.CommandBars("cell").Controls
If icbc.Tag = "brccm" Then icbc.Delete
Next icbc
If Not Application.Intersect(Target, Range("b1:b10")) _
Is Nothing Then
With Application.CommandBars("cell").Controls _
.Add(Type:=msoControlButton, before:=6, _
temporary:=True)
.Caption = "New Context Menu Item"
.OnAction = "MyMacro"
.Tag = "brccm"
End With
End If
End Sub
Applies to | Chart Object | Worksheet Object
See Also | BeforeDoubleClick Event | SheetBeforeDoubleClick Event | SheetBeforeRightClick Event