Private Sub CreateContextMenu()
Const strMenuName As String = "Form1_CommandBar"
Dim cbar As CommandBar
Dim bt As CommandBarButton
Set cbar = CommandBars.Add(strMenuName, msoBarPopup, , False)
Set bt = cbar.Controls.Add
bt.Caption = "Cut"
bt.OnAction = "=fCut()"
bt.FaceId = 21
Set bt = cbar.Controls.Add
bt.Caption = "Copy"
bt.OnAction = "=fCopy()"
bt.FaceId = 19
Set bt = cbar.Controls.Add
bt.Caption = "Paste"
bt.OnAction = "=fPaste()"
bt.FaceId = 22
End Sub
Function fCut()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Cut")
End Function
Function fCopy()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Copy")
End Function
Function fPaste()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Paste")
End Function
Function CommandBarExists(Name As String) As Boolean
On Error Resume Next
CommandBarExists = TypeName(CommandBars(Name)) = "Form1_CommandBar"
End Function