Right click copy/past - textbox in userform

perksukataus

Board Regular
Joined
Aug 29, 2007
Messages
78
Hi guys, any help greatly appreciated.

I have created a userform that people complete to add data to a spreadsheet. Some users have complained they are unable to right click in the text boxes to paste information copied from elsewhere. Yes they can ctrl v, but this appears a little to difficult to remember.

Does anybody know how to add this right click option to text boxes ?

Thanks !
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In the userform module; modify for textbox name:

Code:
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
SendKeys "^v"
End Sub
 
Upvote 0
Thanks for looking into this for me.

This code just pastes what is stored in the clipboard when the right mouse button is clicked. I was actually wondering if it's possible to get the menu when right clicking (same menu as when you right click on a cell) ?
 
Upvote 0
First, isn't Paste what you asked for in your first post, and second, why would you want a menu, since textboxes do not support rich text format. All you can do is put text in them, formatted a certain way that affects all the text, therefore Paste is all you can do anyway.
 
Upvote 0
Tom, the users are used to right clicking and selecting paste from a list of options. I wondered if I can make this list of options available when right clicking in the text box.

I understand that the only option would be paste.

Thanks for your help anyways.
 
Upvote 0
So you want to design the userform such that a menu pops up that lists items, among them Paste, when Paste is all they can do? What if they expect that clicking on some other options should "do something because it's there"?

And it means they must click at least twice instead of once, the first time being the right click for a menu, and the second time for left-clicking the Paste option which is all they can do anyway. I would not post the code for that, it doesn't make sense for a user friendly design to put items on a custom menu that are not available.

The most you would want to have is just a "Paste" menu option instead of a list of other options even though they are used to seeing whatever menu items they are used to seeing. We can discuss that, and I'm not trying to be difficult with you, but I wouldn't do a custom menu list of items that has no relevance to the control.
 
Upvote 0
Hi again,

Absolutely understand where your coming from. I'll educate users to use Ctrl V.

Thanks again for your help.

Josh
 
Upvote 0
That will probably not work either, if they are accustomed to right-clicking.

Do this:

In the userform module, delete that first procedure I posted and put this into the module:

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 Run "MyRightClickMenu"
End Sub
 
Private Sub UserForm_Terminate()
Application.CommandBars("Cell").Reset
End Sub



In a new standard module (such as macros and UDFs go in), paste this in:

Code:
Private Sub MyRightClickMenu()
Application.CommandBars("Cell").Reset
Dim cbc As CommandBarControl
For Each cbc In Application.CommandBars("cell").Controls
cbc.Visible = False
Next cbc
With Application.CommandBars("Cell").Controls.Add(temporary:=True)
.Caption = "Paste"
.OnAction = "myPaste"
End With
Application.CommandBars("Cell").ShowPopup
End Sub
 
Private Sub myPaste()
SendKeys "^v"
End Sub


That should meet most people's comfort level.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top