Highlight text in Textbox

  • Thread starter Thread starter jnf40
  • Start date Start date
Normally, you would put this code...

TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
TextBox1.SetFocus

in the UserForm's Activate event. HOWEVER, there seems to be a problem if
TextBox1 was the last control to have had focus when the UserForm was
deactivated... for some reason, the text will not be highlighted under these
conditions when you return to the UserForm. So, either make sure some other
control has focus when the UserForm is deactivated or simply use this code
in place of the above code...

SendKeys "{TAB}+{TAB}"
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)

Of course, this requires at least one other control capable of taking focus
to be on the UserForm.

Rick
 
How do you get the text in a textbox to be highlighted when the userform
activates?

Set the index number of that text box to zero so it is the first
active object when the userform loads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top