How to select the contents of a textbox once it is activated?

前端 未结 10 2187
灰色年华
灰色年华 2020-12-06 05:16

I have this simple Userform, where I only have TextBox1 and TextBox2. I enter some text in both of them. Assume the focus is on (the cursor is in)

10条回答
  •  自闭症患者
    2020-12-06 05:44

    Try the same code with TextBox1_MouseDown. It should work.

    Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        With TextBox1
            .SetFocus
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
        MsgBox "Text in TextBox1 is selected"
    End Sub
    

提交回复
热议问题