Consulting

Results 1 to 3 of 3

Thread: right-click in textbox

  1. #1

    right-click in textbox

    I have a userform textbox. Is it not possible to right-click in a textbox so I can use the paste option from the menu that appears? If so, how do I enable this feature. I can right-click on the sheet, but can't do it in the userform textbox. I know I can use CTRL+V, but not all user are computer savvy. Thanks

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    There is no RightClick event for a userform's textbox, but you can use the MouseUp event

    [VBA]Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    If Button = 2 Then
    MsgBox "You right clicked"
    End If
    End Sub[/VBA]

    To paste to the textbox, one needs to use a DataObject object.

    [VBA]Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    Dim ClipboardData As New DataObject
    Dim strClipboard As String

    If Button = 2 Then
    ClipboardData.GetFromClipboard
    strClipboard = ClipboardData.GetText(1)
    For i = 1 To Len(strClipboard)
    Cells(i, 1) = Mid(strClipboard, i, 1)
    Next i
    If strClipboard <> vbNullString Then
    strClipboard = Left(strClipboard, InStr(strClipboard & Chr(3) & Chr(197), Chr(3) & Chr(197)))
    TextBox1.Text = strClipboard
    End If
    End If
    End Sub
    [/VBA]
    Last edited by mikerickson; 07-27-2011 at 01:17 AM.

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Users that don't know how to paste with Ctrl+V or the Windows standard Shift+Ins will probably have lots of problems. You could add a label to give them a tip or a controltiptext or a drop option or a combination of those options. Here is the controltiptext and drop option example.
    [vba]'Textbox drop example: http://peltiertech.com/WordPress/ref...l-alternative/
    Private Sub UserForm_Initialize()
    TextBox1.DropButtonStyle = fmDropButtonStyleArrow
    TextBox1.ShowDropButtonWhen = fmShowDropButtonWhenFocus
    End Sub

    Private Sub TextBox1_DropButtonClick()
    Dim rc As Integer
    rc = MsgBox("Paste Text?", vbQuestion + vbYesNo, "Paste Option")
    If rc = vbYes Then TextBox1.Paste
    TextBox2.SetFocus
    TextBox1.SetFocus
    End Sub

    Private Sub TextBox1_Enter()
    TextBox1.ControlTipText = "Press Ctrl+V to Paste"
    End Sub
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •