Highlight (ie Select characters in a textbox)

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

Is there a way with programming to select a certain string of characters in a
Form TextBox. For example: Lets say the TextBox's value is:

"This is the example I want to use."

Is there a way without using the mouse to highlight the word example in that
phrase.

Thank you,

Steven
 
Change the TextBox's HideSelection property to False (otherwise you would
have to set focus to the TextBox in order to see the highlight) and then use
the SelStart and SelLength properties of the TextBox to highlight the text.
Here is some example code...

Dim Word As String
Word = "example"
With Me.TextBox1
.SelStart = InStr(1, .Text, Word, vbTextCompare) - 1
.SelLength = Len(Word)
End With
 

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