Context menu on userform

G

Guest

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
 
B

Bob Phillips

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)
 
G

Guest

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
 
T

Tom Ogilvy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top