Hi,
How can I have the ability to right-click in a textbox? Currently when I right-click, nothing happens. What I would like is to have the user be able to right-click and then copy the text from the textbox.
Any ideas
Cheers,
Hi,
How can I have the ability to right-click in a textbox? Currently when I right-click, nothing happens. What I would like is to have the user be able to right-click and then copy the text from the textbox.
Any ideas
Cheers,
Previous thread
http://www.excelforum.com/excel-prog...-userform.html
why not post your workbook then
The code works fine. here's the code in a workbook
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
Ok I've gotten a code after googling for a while, and I got a menu to come up when I right-click in a textbox (menu consists of copy and paste selections).
Now the only problem is, even after I highlight the text, right-click, and hit copy, nothing is copied to the clipboard!
Here's the code I have ... one is for the userform code, and the other is for the module:
UserForm
Module![]()
' Right-Click Menu Private Sub TextBox1_GotFocus() Set ctl = TextBox1 End Sub Private Sub tbFranchiseNumber_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = vbKeyRButton Then Call ShowTextMenu End Sub Sub ShowTextMenu() Call MakeMenu Application.CommandBars("TextBox Bar").ShowPopup End Sub Sub MakeMenu() On Error Resume Next CommandBars("TextBox Bar").Delete On Error GoTo 0 Dim cbTextBox As CommandBar Dim cmdTest As CommandBarButton Set cbTextBox = Application.CommandBars.Add(Name:="TextBox Bar", Position:=msoBarPopup, Temporary:=True) With cbTextBox For b = 1 To 2 Set cmdTest = .Controls.Add(Type:=msoControlButton, Temporary:=True) With cmdTest .Style = msoButtonIconAndCaption .Parameter = b Select Case b Case 1 .FaceId = 19 .Caption = "Copy" Case 2 .FaceId = 22 .Caption = "Paste" End Select .OnAction = "TextMenu" End With Next b End With End Sub
Any ideas![]()
Public txtData As DataObject Public ctl As Object Public Sub TextMenu() Dim ctlCBarControl As CommandBarControl Dim i As Integer Dim s As Long Set ctlCBarControl = CommandBars.ActionControl If ctlCBarControl Is Nothing Then Exit Sub i = CInt(ctlCBarControl.Parameter) With UserForm1 Select Case i Case 1 Set txtData = New DataObject txtData.SetText .TextBox1.SelText txtData.PutInClipboard If i = 1 Then s = .TextBox1.SelStart .TextBox1 = Left(.TextBox1, .TextBox1.SelStart) & _ Mid(.TextBox1, .TextBox1.SelStart + _ .TextBox1.SelLength + 1) .TextBox1.SelStart = s End If Case 2 .TextBox1.Paste End Select End With End Sub
![]()
Do you have macros called "Copy" & "Paste"? What do you want to copy & paste?
Attach the workbook
Your are using inconsistent references.
is it Textbox1 or tbFranchiseNumber ?
Also your copy section of TextMenu actually Cuts the selected text after copying.![]()
Private Sub TextBox1_GotFocus() Set ctl = TextBox1 End Sub Private Sub tbFranchiseNumber_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = vbKeyRButton Then Call ShowTextMenu End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks