Finance

Charts

Statistics

Macros

Search

Macro to Highlight the Contents of Text Fields in a UserForm, Excel VBA

Use the following macro to highlight the saved content of a text field. For this task, you need a UserForm with a text box and a button. In the development environment, double-click the button and insert the following code:

Private Sub CommandButton1_Click()
    TextBox1.SetFocus
    TextBox1.SelStart = 0
    TextBox1.SelLength = Len(TextBox1.Text)
End Sub

Use the SetFocus method to place the mouse pointer on the text field. With the SelStart property, you determine the starting position of the text to be highlighted. The SelLength property defines the number of characters to highlight. Assign the Len function to this property, which determines the total number of characters entered in the text field.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx