Before Right Click showpopup menu
I've been trying to get the code below to produce a menu on right click from a spreadsheet but it always ends in an error on the line
CommandBars("Data Popup").ShowPopup
but I can't work out why.
Do the two routines need to be in specific places for it to work? What am I missing?
Thanks
Dave
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("database"), Target) Is Nothing Then
CommandBars("Data Popup").ShowPopup
Cancel = True
End If
End Sub
Sub MakePopup()
'Get rid of any existing toolbar called Data Popup
On Error Resume Next
CommandBars("Data Popup").Delete
On Error GoTo 0
'Add new popup commandbar
With CommandBars.Add(Name:="Data Popup", Position:=msopopup)
'Add controls
With .Controls.Add(Type:=msoControlButton)
.OnAction = "ShowDataForm"
.FaceId = 264
.Caption = "Data Form"
.TooltipText = "Show Data Form"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Sort Ascending"
.FaceId = 210
.OnAction = "SortList"
.Parameter = "Asc"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Sort Decending"
.FaceId = 211
.OnAction = "SortList"
.Parameter = "Dsc"
End With
End With
End Sub
|