‘ Given an editable textbox named Text1, this code prompts to find a word and
‘ searches throught the textbox and highlights the first occurance of the
‘ found word (if exists).
Original Author: Bill Chelonis
Code
Private Sub FindFunction_Click()
Rem Find/highlight first occurance of a word in a textbox named Text1
Dim a As String
Dim y As Integer
a = InputBox("Find text: ", "Find", "")
Call Text1.SetFocus
SendKeys ("^{HOME}")
y = 1
Do Until y = Len(Text1.text)
Rem check if word was located
If Mid(UCase$(Text1.text), y, Len(a)) = UCase$(a) Then
Rem highlight the found word and exit sub
For x = 1 To Len(a)
SendKeys ("+{RIGHT}")
Next x
Exit Do
End If
Rem do nothing if carriage return encountered else highlight found word
If Mid(Text1.text, y, 1) = Chr$(13) Then
Else
Rem move the cursor to the next element of text
SendKeys ("{RIGHT}")
End If
y = y + 1
If y > Len(Text1.text) Then Exit Do
Loop
End Sub