Monday, May 2, 2016

How to highlight the text of a Userform Textbox at mouse click in EXCEL VBA

First create a userform with a text box (Pic 1, pic 2, pic 3)




In the code of the userform, write following code:

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    With UserForm1.TextBox1
        .SelStart = 0
        .SelLength = Len(.Text)
        .ForeColor = &H80000001
    End With
End Sub

Now, whenever the user click on the textbox, it will highlight the text inside automatically



No comments:

Post a Comment