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?
Sure thing!
Now you can call this function like this:Code:Public Sub ColorWords(pRich As RichTextBox, pWord As String, pColor As OLE_COLOR)
Dim iPos As Integer
With pRich
iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
Do While iPos <> 0
.SelStart = iPos - 1
.SelLength = Len(pWord)
.SelColor = pColor
iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
Loop
End With
End Sub
Code:Private Sub Command1_Click()
ColorWords RichTextBox1, "Private", vbBlue
End Sub