Function HtmlEscape(strRawData) 'As String 'Escapes data to make it html-safe Dim strHtmlEscape 'As String strHtmlEscape = strRawData strHtmlEscape = Replace(strHtmlEscape, "&", "&") strHtmlEscape = Replace(strHtmlEscape, "<", "<") strHtmlEscape = Replace(strHtmlEscape, ">", ">") strHtmlEscape = Replace(strHtmlEscape, """", """) strHtmlEscape = Replace(strHtmlEscape, vbCrLf, "
") strHtmlEscape = Replace(strHtmlEscape, vbCr, "
") strHtmlEscape = Replace(strHtmlEscape, vbLf, "
") strHtmlEscape = Replace(strHtmlEscape, vbTab, "    ") strHtmlEscape = Replace(strHtmlEscape, " ", "  ") HtmlEscape = strHtmlEscape End Function Function UnescapeHtml(strHtml) Dim strOut, strChar Dim lngLength, lngPosition, lngChar strOut = strHtml 'Replace decimal and unicode escapes. Allow for a few typical improper Microsoft codes. lngPosition = Instr(strOut, "&#") Do While lngPosition <> 0 'Get the number after the &# sequence strChar = FirstNumber(Mid(strOut, lngPosition, 6)) lngLength = Len("&#" & strChar) 'Is there a trailing semicolon? If Mid(strOut, lngPosition + lngLength, 1) = ";" Then lngLength = lngLength + 1 End If 'Convert the number after &# to an ASCII or Unicode character lngChar = CLng(strChar) If lngChar > 255 Then strChar = ChrW(lngChar) Else strChar = Chr(lngChar) End If 'Replace the escaped sequence with the actual character strOut = Left(strOut, lngPosition - 1) & strChar & Mid(strOut, lngPosition + lngLength) lngPosition = Instr(strOut, "&#") Loop 'Replace the other escapes Do While Instr(strOut, """) <> 0 : strOut = Replace(strOut, """, Chr(34)) : Loop Do While Instr(strOut, "&") <> 0 : strOut = Replace(strOut, "&", Chr(38)) : Loop Do While Instr(strOut, "<") <> 0 : strOut = Replace(strOut, "<", Chr(60)) : Loop Do While Instr(strOut, ">") <> 0 : strOut = Replace(strOut, ">", Chr(62)) : Loop 'Allow for Microsoft's improper escaping of these 4 characters Do While Instr(strOut, """) <> 0 : strOut = Replace(strOut, """, Chr(34)) : Loop Do While Instr(strOut, "&") <> 0 : strOut = Replace(strOut, "&", Chr(38)) : Loop Do While Instr(strOut, "<") <> 0 : strOut = Replace(strOut, "<", Chr(60)) : Loop Do While Instr(strOut, ">") <> 0 : strOut = Replace(strOut, ">", Chr(62)) : Loop Do While Instr(strOut, "À") <> 0 : strOut = Replace(strOut, "À", Chr(192)) : Loop Do While Instr(strOut, "Â") <> 0 : strOut = Replace(strOut, "Â", Chr(194)) : Loop Do While Instr(strOut, "Ä") <> 0 : strOut = Replace(strOut, "Ä", Chr(196)) : Loop Do While Instr(strOut, "Æ") <> 0 : strOut = Replace(strOut, "Æ", Chr(198)) : Loop Do While Instr(strOut, "È") <> 0 : strOut = Replace(strOut, "È", Chr(200)) : Loop Do While Instr(strOut, "Ê") <> 0 : strOut = Replace(strOut, "Ê", Chr(202)) : Loop Do While Instr(strOut, "Ì") <> 0 : strOut = Replace(strOut, "Ì", Chr(204)) : Loop Do While Instr(strOut, "Î") <> 0 : strOut = Replace(strOut, "Î", Chr(206)) : Loop Do While Instr(strOut, "Ò") <> 0 : strOut = Replace(strOut, "Ò", Chr(210)) : Loop Do While Instr(strOut, "Ô") <> 0 : strOut = Replace(strOut, "Ô", Chr(212)) : Loop Do While Instr(strOut, "Ö") <> 0 : strOut = Replace(strOut, "Ö", Chr(214)) : Loop Do While Instr(strOut, "Ø") <> 0 : strOut = Replace(strOut, "Ø", Chr(216)) : Loop Do While Instr(strOut, "Ú") <> 0 : strOut = Replace(strOut, "Ú", Chr(218)) : Loop Do While Instr(strOut, "Ü") <> 0 : strOut = Replace(strOut, "Ü", Chr(220)) : Loop Do While Instr(strOut, "Þ") <> 0 : strOut = Replace(strOut, "Þ", Chr(222)) : Loop Do While Instr(strOut, "à") <> 0 : strOut = Replace(strOut, "à", Chr(224)) : Loop Do While Instr(strOut, "â") <> 0 : strOut = Replace(strOut, "â", Chr(226)) : Loop Do While Instr(strOut, "ä") <> 0 : strOut = Replace(strOut, "ä", Chr(228)) : Loop Do While Instr(strOut, "æ") <> 0 : strOut = Replace(strOut, "æ", Chr(230)) : Loop Do While Instr(strOut, "è") <> 0 : strOut = Replace(strOut, "è", Chr(232)) : Loop Do While Instr(strOut, "ê") <> 0 : strOut = Replace(strOut, "ê", Chr(234)) : Loop Do While Instr(strOut, "ì") <> 0 : strOut = Replace(strOut, "ì", Chr(236)) : Loop Do While Instr(strOut, "î") <> 0 : strOut = Replace(strOut, "î", Chr(238)) : Loop Do While Instr(strOut, "ð") <> 0 : strOut = Replace(strOut, "ð", Chr(240)) : Loop Do While Instr(strOut, "ò") <> 0 : strOut = Replace(strOut, "ò", Chr(242)) : Loop Do While Instr(strOut, "ô") <> 0 : strOut = Replace(strOut, "ô", Chr(244)) : Loop Do While Instr(strOut, "ö") <> 0 : strOut = Replace(strOut, "ö", Chr(246)) : Loop Do While Instr(strOut, "ø") <> 0 : strOut = Replace(strOut, "ø", Chr(248)) : Loop Do While Instr(strOut, "ú") <> 0 : strOut = Replace(strOut, "ú", Chr(250)) : Loop Do While Instr(strOut, "ü") <> 0 : strOut = Replace(strOut, "ü", Chr(252)) : Loop Do While Instr(strOut, "þ") <> 0 : strOut = Replace(strOut, "þ", Chr(254)) : Loop Do While Instr(strOut, "Á") <> 0 : strOut = Replace(strOut, "Á", Chr(193)) : Loop Do While Instr(strOut, "Ã") <> 0 : strOut = Replace(strOut, "Ã", Chr(195)) : Loop Do While Instr(strOut, "Å") <> 0 : strOut = Replace(strOut, "Å", Chr(197)) : Loop Do While Instr(strOut, "Ç") <> 0 : strOut = Replace(strOut, "Ç", Chr(199)) : Loop Do While Instr(strOut, "É") <> 0 : strOut = Replace(strOut, "É", Chr(201)) : Loop Do While Instr(strOut, "Ë") <> 0 : strOut = Replace(strOut, "Ë", Chr(203)) : Loop Do While Instr(strOut, "Í") <> 0 : strOut = Replace(strOut, "Í", Chr(205)) : Loop Do While Instr(strOut, "Ï") <> 0 : strOut = Replace(strOut, "Ï", Chr(207)) : Loop Do While Instr(strOut, "Ñ") <> 0 : strOut = Replace(strOut, "Ñ", Chr(209)) : Loop Do While Instr(strOut, "Ó") <> 0 : strOut = Replace(strOut, "Ó", Chr(211)) : Loop Do While Instr(strOut, "Õ") <> 0 : strOut = Replace(strOut, "Õ", Chr(213)) : Loop Do While Instr(strOut, "Ù") <> 0 : strOut = Replace(strOut, "Ù", Chr(217)) : Loop Do While Instr(strOut, "Û") <> 0 : strOut = Replace(strOut, "Û", Chr(219)) : Loop Do While Instr(strOut, "Ý") <> 0 : strOut = Replace(strOut, "Ý", Chr(221)) : Loop Do While Instr(strOut, "ß") <> 0 : strOut = Replace(strOut, "ß", Chr(223)) : Loop Do While Instr(strOut, "á") <> 0 : strOut = Replace(strOut, "á", Chr(225)) : Loop Do While Instr(strOut, "ã") <> 0 : strOut = Replace(strOut, "ã", Chr(227)) : Loop Do While Instr(strOut, "å") <> 0 : strOut = Replace(strOut, "å", Chr(229)) : Loop Do While Instr(strOut, "ç") <> 0 : strOut = Replace(strOut, "ç", Chr(231)) : Loop Do While Instr(strOut, "é") <> 0 : strOut = Replace(strOut, "é", Chr(233)) : Loop Do While Instr(strOut, "ë") <> 0 : strOut = Replace(strOut, "ë", Chr(235)) : Loop Do While Instr(strOut, "í") <> 0 : strOut = Replace(strOut, "í", Chr(237)) : Loop Do While Instr(strOut, "ï") <> 0 : strOut = Replace(strOut, "ï", Chr(239)) : Loop Do While Instr(strOut, "ñ") <> 0 : strOut = Replace(strOut, "ñ", Chr(241)) : Loop Do While Instr(strOut, "ó") <> 0 : strOut = Replace(strOut, "ó", Chr(243)) : Loop Do While Instr(strOut, "õ") <> 0 : strOut = Replace(strOut, "õ", Chr(245)) : Loop Do While Instr(strOut, "ù") <> 0 : strOut = Replace(strOut, "ù", Chr(249)) : Loop Do While Instr(strOut, "û") <> 0 : strOut = Replace(strOut, "û", Chr(251)) : Loop Do While Instr(strOut, "ý") <> 0 : strOut = Replace(strOut, "ý", Chr(253)) : Loop Do While Instr(strOut, "ÿ") <> 0 : strOut = Replace(strOut, "ÿ", Chr(255)) : Loop UnescapeHtml = strOut End Function