I've made a basic function that adds some HTML tags to my rich text boxes based on what I want to display to the user, E.G. red / bold text for warnings etc...
Below is the main function & some examples of how I use it.
It's not very sophisticated but it's served me well so far & I wanted to share it. If anyone has any suggestions for improvements would love to hear back!
Below is the main function & some examples of how I use it.
It's not very sophisticated but it's served me well so far & I wanted to share it. If anyone has any suggestions for improvements would love to hear back!
Code:
Option Explicit
Public Enum udtHTMLTags
bwBold = 1
bwItalic = 2
bwUnderline = 4
bwLineBreak = 8
End Enum
Public Function fnAddHTML(strInput As String, Optional HtmlTags As udtHTMLTags, Optional strColour = vbNullString) As String
Dim strStart As String, strEnd As String
If HtmlTags And bwBold Then
strStart = "<b>"
strEnd = "</b>"
End If
If HtmlTags And bwItalic Then
strStart = strStart & "<i>"
strEnd = strEnd & "</i>"
End If
If HtmlTags And bwUnderline Then
strStart = strStart & "<u>"
strEnd = strEnd & "</u>"
End If
If strColour <> vbNullString Then
strStart = strStart & "<font color=" & Chr(34) & strColour & Chr(34) & ">"
strEnd = strEnd & "</font>"
End If
If HtmlTags And bwLineBreak Then
fnAddHTML = strStart & strInput & strEnd & "<br>"
Else
fnAddHTML = strStart & strInput & strEnd
End If
End Function
Public Function fnRedText(strWarningMessage As String) As String
fnRedText = fnAddHTML("Warning: ", , "FF0000") & strWarningMessage
End Function
Public Sub PrintText()
Dim strPrintText As String
strPrintText = fnAddHTML("Some bold text", bwBold)
Debug.Print strPrintText
strPrintText = fnAddHTML("Some bold & underlined", bwBold + bwUnderline)
Debug.Print strPrintText
strPrintText = fnAddHTML("All the options", bwBold + bwItalic + bwUnderline + bwLineBreak, "00FF00")
Debug.Print strPrintText
End Sub