This is another example of how to colour HTML tags. Add a RichTextBox to your form, and a command button called cmdColour. Then use the following code
Private Sub ColorHTML(RTF As RichTextBox)
Dim sHTML As String
Dim nTagOpen As Long
Dim nTagClose As Long
Dim nI As Long
Dim nColor As Long
sHTML = RTF.Text
nTagClose = 1
With RTF
For nI = 1 To Len(sHTML)
' *** See where the next tag
starts.
nTagOpen = InStr(nTagClose,
sHTML, "<")
If nTagOpen = 0 Then Exit For
If LCase(Mid(sHTML, nTagOpen,
4)) = "<img" Then
nColor =
&H400040
ElseIf LCase(Mid(sHTML,
nTagOpen, 2)) = "<a" Then
nColor =
&H8080&
ElseIf LCase(Mid(sHTML,
nTagOpen, 2)) = "<b" Then
nColor =
&H8000000F
Else
nColor =
&H4000&
End If
' *** See where the tag ends.
nTagClose = InStr(nTagOpen,
sHTML, ">")
If nTagOpen = 0 Then nTagClose
= Len(sHTML)
If nTagClose = 0 Then nTagClose
= Len(sHTML)
' *** Color the tag.
.SelStart = nTagOpen - 1
.SelLength = nTagClose -
nTagOpen + 1
.SelColor = nColor
Next
End With
End Sub
Private Sub cmdColour_Click()
ColorHTML RichTextBox1
End Sub
Comments