![]() |
Context menu on userform
I have a userform with a load of text boxes for entering and editing data. I
want the ability to right click on a textbox in the form and choose cut, copy or paste. When I right click on a textbox at the moment I get no menu at all. CTRL X,C and V work but I want the right click enabled. Is this possible? TIA |
Context menu on userform
Here is a technique posted by John Green last year
A short cut menu can be created as a popup commandbar. The menu can be activated from the MouseUp event of the textbox. You can create a popup menu using code like the following in a standard module. -------------------------------------------------------------------------- Sub MakePopUp() 'Remove any old instance of MyPopUp On Error Resume Next CommandBars("MyPopUp").Delete On Error GoTo 0 With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup) With .Controls.Add(Type:=msoControlButton) .OnAction = "ShowDataForm" .FaceId = 264 .Caption = "Data Form" End With With .Controls.Add(Type:=msoControlButton) .OnAction = "Sort" .FaceId = 210 .Caption = "Sort Ascending" End With End With End Sub Sub ShowDataForm() MsgBox "DataForm" End Sub Sub Sort() MsgBox "Sort" End Sub ---------------------------------------------------------------------- In your userform code module choose the Textbox from the top left dropdown and the MouseUp event from the top right dropdown and insert something like the following code: ---------------------------------------------------------------------------- Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 2 Then Application.CommandBars("MyPopUp").ShowPopup End If End Sub --------------------------------------------------------------------------- -- HTH RP (remove nothere from the email address if mailing direct) "Matthew" wrote in message ... I have a userform with a load of text boxes for entering and editing data. I want the ability to right click on a textbox in the form and choose cut, copy or paste. When I right click on a textbox at the moment I get no menu at all. CTRL X,C and V work but I want the right click enabled. Is this possible? TIA |
Context menu on userform
Thanks Bob,
I'm a bit of a newbie and thought that I would be able to turn on the context menu somewhere and Excel would give me the default Cut, Copy and Paste options. I am going to need help writing the code if indeed this is what I need to do to get it to work. TIA Matthew "Bob Phillips" wrote: Here is a technique posted by John Green last year A short cut menu can be created as a popup commandbar. The menu can be activated from the MouseUp event of the textbox. You can create a popup menu using code like the following in a standard module. -------------------------------------------------------------------------- Sub MakePopUp() 'Remove any old instance of MyPopUp On Error Resume Next CommandBars("MyPopUp").Delete On Error GoTo 0 With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup) With .Controls.Add(Type:=msoControlButton) .OnAction = "ShowDataForm" .FaceId = 264 .Caption = "Data Form" End With With .Controls.Add(Type:=msoControlButton) .OnAction = "Sort" .FaceId = 210 .Caption = "Sort Ascending" End With End With End Sub Sub ShowDataForm() MsgBox "DataForm" End Sub Sub Sort() MsgBox "Sort" End Sub ---------------------------------------------------------------------- In your userform code module choose the Textbox from the top left dropdown and the MouseUp event from the top right dropdown and insert something like the following code: ---------------------------------------------------------------------------- Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 2 Then Application.CommandBars("MyPopUp").ShowPopup End If End Sub --------------------------------------------------------------------------- -- HTH RP (remove nothere from the email address if mailing direct) "Matthew" wrote in message ... I have a userform with a load of text boxes for entering and editing data. I want the ability to right click on a textbox in the form and choose cut, copy or paste. When I right click on a textbox at the moment I get no menu at all. CTRL X,C and V work but I want the right click enabled. Is this possible? TIA |
Context menu on userform
if indeed this is
what I need to do to get it to work. Sounds like you are still in doubt. So to clear it up: There is no setting you can turn on to do what you want. You have to program it. -- Regards, Tom Ogilvy "Matthew" wrote in message ... Thanks Bob, I'm a bit of a newbie and thought that I would be able to turn on the context menu somewhere and Excel would give me the default Cut, Copy and Paste options. I am going to need help writing the code if indeed this is what I need to do to get it to work. TIA Matthew "Bob Phillips" wrote: Here is a technique posted by John Green last year A short cut menu can be created as a popup commandbar. The menu can be activated from the MouseUp event of the textbox. You can create a popup menu using code like the following in a standard module. -------------------------------------------------------------------------- Sub MakePopUp() 'Remove any old instance of MyPopUp On Error Resume Next CommandBars("MyPopUp").Delete On Error GoTo 0 With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup) With .Controls.Add(Type:=msoControlButton) .OnAction = "ShowDataForm" .FaceId = 264 .Caption = "Data Form" End With With .Controls.Add(Type:=msoControlButton) .OnAction = "Sort" .FaceId = 210 .Caption = "Sort Ascending" End With End With End Sub Sub ShowDataForm() MsgBox "DataForm" End Sub Sub Sort() MsgBox "Sort" End Sub ---------------------------------------------------------------------- In your userform code module choose the Textbox from the top left dropdown and the MouseUp event from the top right dropdown and insert something like the following code: -------------------------------------------------------------------------- -- Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 2 Then Application.CommandBars("MyPopUp").ShowPopup End If End Sub -------------------------------------------------------------------------- - -- HTH RP (remove nothere from the email address if mailing direct) "Matthew" wrote in message ... I have a userform with a load of text boxes for entering and editing data. I want the ability to right click on a textbox in the form and choose cut, copy or paste. When I right click on a textbox at the moment I get no menu at all. CTRL X,C and V work but I want the right click enabled. Is this possible? TIA |
All times are GMT +1. The time now is 08:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com