In the worksheet's code module (right-click the sheet tab, and choose View Code):
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' cancel default shortcut menu
Cancel = True
ShowPopupMenu
End Sub
then in a normal module:
Sub ShowPopupMenu()
Const cstrBarName As String = "MyCellPopup"
Dim cbr As CommandBar, ctl As CommandBarControl
On Error Resume Next
Application.CommandBars(cstrBarName).Delete
On Error GoTo err_handler
' add new popup menu
Set cbr = Application.CommandBars.Add(cstrBarName, msoBarPopup, , True)
' add a couple of buttons
Set ctl = cbr.Controls.Add
With ctl
.Caption = "Macro1"
.OnAction = "'" & ThisWorkbook.Name & "'!macro1"
.Style = msoButtonCaption
End With
Set ctl = cbr.Controls.Add
With ctl
.Caption = "Macro2"
.OnAction = "'" & ThisWorkbook.Name & "'!macro2"
.Style = msoButtonCaption
End With
cbr.ShowPopup
cbr.Delete
Exit Sub
err_handler:
MsgBox Err.Description
End Sub
adjust the number of controls and macro names as required.
Bookmarks