in the userform code-module:
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
MakePopUp
Application.CommandBars("MyPopUp").ShowPopup
End If
End Sub
In a Standard code-module:
Sub Coyp() '(obj As Object)
MsgBox "DataForm " ' & obj.Name
End Sub
Sub MakePopUp() '(obj As Object)
'Remove any old instance of MyPopUp
Excel.Application.CommandBars("MyPopUp").Delete
With Excel.Application.CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup)
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Coyp" '"Coyp" '
.FaceId = 19
.Caption = "Copy"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "Paste"
.FaceId = 21
.Caption = "Paste"
End With
End With
End Sub
For the moment, I've commented out the obj you seem to be trying to pass around, because I'm not sure what the intention is (are you trying to get this working with multiple textboxes on the userform by using a class module?). As it stands it works on a right-click of the text box called TextBox1
As you can see my textbox's name was TextBox1
Private Sub TextBox1_MouseUp(ByVal B…
You should make sure the event handler is properly matched to your textbox too.
I'm guessing you got this code from the internet? Can you provide a link?
Oh, and what version of Excel are you using?