I have a rich text box that a whole bunch of text gets poured into, I want this text box to check to see if the word "private" is typed in, if it is I want it changed to blue. Any idea how to do this?
Printable View
I have a rich text box that a whole bunch of text gets poured into, I want this text box to check to see if the word "private" is typed in, if it is I want it changed to blue. Any idea how to do this?
Code:Private Sub RichTextBox1_Change()
Static lngStart As Long
Dim lngFound As Long
Dim intLen As Integer
Const LOOK_FOR = "PRIVATE"
intLen = Len(LOOK_FOR)
If lngStart = 0 Then
lngStart = 1
End If
lngFound = InStr(lngStart, UCase(RichTextBox1.Text), LOOK_FOR)
If lngFound > 0 Then
RichTextBox1.SelStart = lngFound - 1
RichTextBox1.SelLength = lngFound + intLen
RichTextBox1.SelColor = vbBlue
RichTextBox1.SelStart = lngFound + intLen + 1
RichTextBox1.SelColor = vbBlack
lngStart = lngFound + intLen
End If
End Sub