PDA

View Full Version : [SOLVED:] How to enable right click paste on more than one TextBox



HTSCF Fareha
11-26-2021, 04:16 AM
As kindly provided by Graham Mayor on a separate thread, I've been using the following attached to enable right mouse click pasting into a TextBox, using the below Sub to enable pasting, in this case, into the TextBox labelled txtEditor.


Private Sub txtEditor_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal x As Single, _
ByVal y As Single)

' If right-button clicked
If Button = 2 Then
Call ShowPopup(Me, Caption, txtEditor, x, y)
End If

lbl_Exit:
Exit Sub
End Sub

This works brilliantly on a single Textbox, but I was wondering how one would be able to utilize it for more than one TextBox on the same UserForm. I can add multiple Subs and changing the Sub name and related TextBox name, but was wondering if there was a more efficient way?

gmayor
11-27-2021, 12:11 AM
Use multiple subs.


Private Sub TextBoxName_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal x As Single, _
ByVal y As Single)

' If right-button clicked
If Button = 2 Then
Call ShowPopup(Me, Caption, TextBoxName, x, y)
End If
lbl_Exit:
Exit Sub
End Sub

HTSCF Fareha
11-27-2021, 01:59 AM
Thanks Graham, I thought that might be the case, but thought that I would ask just in case.