Announcement

Collapse
No announcement yet.

Highlighting Text In Userform Textbox

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Highlighting Text In Userform Textbox



    Hi Guys,

    I have a couple of textboxes on a userform and I want the text to automatically highlight for a certain selection when the user clicks into them.

    I have found a few examples where the text can be selected either when the form is loaded or by clicking a command button but this isn't quite what I need.

    I presume it will be a manipulation of the '.selstart' and '.sellength' properties in an 'Enter' event on the textbox, but I can't quite get it to work myself

    Any help always appreciated.

    Thanks,
    Ian
    Last edited by IanDunnett; October 9th, 2006, 17:35.

  • #2
    Re: Highlighting Text In Userform Textbox

    Create a userform with a textbox and commandbutton.
    This should highlight the word test. Use tab key to move between controls.
    Private Sub TextBox1_Enter()

    Dim lngPos As Long

    lngPos = InStr(TextBox1.Text, "test")
    If lngPos > 0 Then
    TextBox1.SelStart = lngPos - 1
    TextBox1.SelLength = Len("test")
    End If

    End Sub
    Private Sub UserForm_Initialize()

    TextBox1.Text = "This is a test of highlighting"
    TextBox1.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection

    End Sub

    Cheers
    Andy

    Comment


    • #3


      Re: Highlighting Text In Userform Textbox

      Ian

      What do you actually want to do?
      Boo!

      Comment

      Working...
      X