| This code will take a searchstring and a textbox, search the textbox, when the word is found, it will highlight it. This is probably how MS Word works. Put this code into a reusable module. EXAMPLE--searchHighlight(text1,"search") Public Function searchHighlight(srchTextBox As textBox, srchString As String) 'on error resume next Dim A As Integer Call srchTextBox.SetFocus SendKeys ("^{HOME}") A = 1 Do Until A = Len(srchTextBox.text) 'if word was found... If Mid(UCase$(srchTextBox.text), A, Len(srchString)) = UCase$(srchString) Then 'highlight the word For A = 1 To Len(srchString) SendKeys ("+{RIGHT}") Next A Exit Do End If 'if word isnt found or a return is found, dont do anything If Mid(srchTextBox.text, A, 1) = Chr$(13) Then Else 'go to next line SendKeys ("{RIGHT}") End If A = A + 1 If A > Len(srchTextBox.text) Then Exit Do Loop End Function |
Search and highlight a string in a textbox |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design