[CODE]
Public Function UnHTML(ByVal OrigText As String) As String
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xType As Long
  Dim xChar1 As String
  
  OrigText = Replace(OrigText, "<br>", vbCrLf)
  Do
    xType = InStr(OrigText, "&")
    If xType = 0& Then
      UnHTML = UnHTML + OrigText
      Exit Do
      Else
      xLong2 = InStr(xType + 1&, OrigText, ";")
      If xLong2 = 0& Then
        UnHTML = UnHTML + OrigText
        Exit Do
        Else
        If Mid(OrigText, xType + 1&, 1&) = "#" Then
          If Mid(OrigText, xType + 2&, 1&) = "x" Then
            xChar1 = "&h" + Mid(OrigText, xType + 3&, xLong2 - xType - 3&)
            xLong1 = Val(xChar1)
            If Not xChar1 = "&h" + Hex(xLong1) Then
              GoTo NoGood
              End If
            Else
            xChar1 = Mid(OrigText, xType + 2&, xLong2 - xType - 2&)
            xLong1 = Val(xChar1)
            If Not xChar1 = LTrim(Str(xLong1)) Then
              If xLong1 > 9& Or Not xChar1 = "0" + LTrim(Str(xLong1)) Then
NoGood:
                UnHTML = UnHTML + Left(OrigText, xLong2)
                GoTo EndNoGood
                End If
              End If
            End If
          Else
          Select Case Mid(OrigText, xType + 1&, xLong2 - xType - 1&)
            Case "quot": xLong1 = 34&
            Case "amp": xLong1 = 38&
            Case "frasl": xLong1 = 47&
            Case "lt": xLong1 = 60&
            Case "gt": xLong1 = 62&
            Case "ndash": xLong1 = 150&
            Case "mdash": xLong1 = 151&
'                Case "nbsp": xLong1 = 160&
            Case "iexcl": xLong1 = 161&
            Case "cent": xLong1 = 162&
            Case "pound": xLong1 = 163&
            Case "curren": xLong1 = 164&
            Case "yen": xLong1 = 165&
            Case "brvbar", "brkbar": xLong1 = 166&
            Case "sect": xLong1 = 167&
            Case "uml", "die": xLong1 = 168&
            Case "copy": xLong1 = 169&
            Case "ordf": xLong1 = 170&
            Case "laquo": xLong1 = 171&
            Case "not": xLong1 = 172&
'                Case "shy": xLong1 = 173&
            Case "reg": xLong1 = 174&
            Case "macr", "hibar": xLong1 = 175&
            Case "deg": xLong1 = 176&
            Case "plusmn": xLong1 = 177&
            Case "sup2": xLong1 = 178&
            Case "sup3": xLong1 = 179&
            Case "acute": xLong1 = 180&
            Case "micro": xLong1 = 181&
            Case "para": xLong1 = 182&
            Case "middot": xLong1 = 183&
            Case "cedil": xLong1 = 184&
            Case "sup1": xLong1 = 185&
            Case "ordm": xLong1 = 186&
            Case "raquo": xLong1 = 187&
            Case "frac14": xLong1 = 188&
            Case "frac12": xLong1 = 189&
            Case "frac34": xLong1 = 190&
            Case "iquest": xLong1 = 191&
            Case "Agrave": xLong1 = 192&
            Case "Aacute": xLong1 = 193&
            Case "Acirc": xLong1 = 194&
            Case "Atilde": xLong1 = 195&
            Case "Auml": xLong1 = 196&
            Case "Aring": xLong1 = 197&
            Case "AElig": xLong1 = 198&
            Case "Ccedil": xLong1 = 199&
            Case "Egrave": xLong1 = 200&
            Case "Eacute": xLong1 = 201&
            Case "Ecirc": xLong1 = 202&
            Case "Euml": xLong1 = 203&
            Case "Igrave": xLong1 = 204&
            Case "Iacute": xLong1 = 205&
            Case "Icirc": xLong1 = 206&
            Case "Iuml": xLong1 = 207&
            Case "ETH": xLong1 = 208&
            Case "Ntilde": xLong1 = 209&
            Case "Ograve": xLong1 = 210&
            Case "Oacute": xLong1 = 211&
            Case "Ocirc": xLong1 = 212&
            Case "Otilde": xLong1 = 213&
            Case "Ouml": xLong1 = 214&
            Case "times": xLong1 = 215&
            Case "Oslash": xLong1 = 216&
            Case "Ugrave": xLong1 = 217&
            Case "Uacute": xLong1 = 218&
            Case "Ucirc": xLong1 = 219&
            Case "Uuml": xLong1 = 220&
            Case "Yacute": xLong1 = 221&
            Case "THORN": xLong1 = 222&
            Case "szlig": xLong1 = 223&
            Case "agrave": xLong1 = 224&
            Case "aacute": xLong1 = 225&
            Case "acirc": xLong1 = 226&
            Case "atilde": xLong1 = 227&
            Case "auml": xLong1 = 228&
            Case "aring": xLong1 = 229&
            Case "aelig": xLong1 = 230&
            Case "ccedil": xLong1 = 231&
            Case "egrave": xLong1 = 232&
            Case "eacute": xLong1 = 233&
            Case "ecirc": xLong1 = 234&
            Case "euml": xLong1 = 235&
            Case "igrave": xLong1 = 236&
            Case "iacute": xLong1 = 237&
            Case "icirc": xLong1 = 238&
            Case "iuml": xLong1 = 239&
            Case "eth": xLong1 = 240&
            Case "ntilde": xLong1 = 241&
            Case "ograve": xLong1 = 242&
            Case "oacute": xLong1 = 243&
            Case "ocirc": xLong1 = 244&
            Case "otilde": xLong1 = 245&
            Case "ouml": xLong1 = 246&
            Case "divide": xLong1 = 247&
            Case "oslash": xLong1 = 248&
            Case "ugrave": xLong1 = 249&
            Case "uacute": xLong1 = 250&
            Case "ucirc": xLong1 = 251&
            Case "uuml": xLong1 = 252&
            Case "yacute": xLong1 = 253&
            Case "thorn": xLong1 = 254&
            Case "yuml": xLong1 = 255&
            
            Case "fnof": xLong1 = 402&
            Case "Alpha": xLong1 = 913&
            Case "Beta": xLong1 = 914&
            Case "Gamma": xLong1 = 915&
            Case "Delta": xLong1 = 916&
            Case "Epsilon": xLong1 = 917&
            Case "Zeta": xLong1 = 918&
            Case "Eta": xLong1 = 919&
            Case "Theta": xLong1 = 920&
            Case "Iota": xLong1 = 921&
            Case "Kappa": xLong1 = 922&
            Case "Lambda": xLong1 = 923&
            Case "Mu": xLong1 = 924&
            Case "Nu": xLong1 = 925&
            Case "Xi": xLong1 = 926&
            Case "Omicron": xLong1 = 927&
            Case "Pi": xLong1 = 928&
            Case "Rho": xLong1 = 929&
            Case "Sigma": xLong1 = 931&
            Case "Tau": xLong1 = 932&
            Case "Upsilon": xLong1 = 933&
            Case "Phi": xLong1 = 934&
            Case "Chi": xLong1 = 935&
            Case "Psi": xLong1 = 936&
            Case "Omega": xLong1 = 937&
            Case "alpha": xLong1 = 945&
            Case "beta": xLong1 = 946&
            Case "gamma": xLong1 = 947&
            Case "delta": xLong1 = 948&
            Case "epsilon": xLong1 = 949&
            Case "zeta": xLong1 = 950&
            Case "eta": xLong1 = 951&
            Case "theta": xLong1 = 952&
            Case "iota": xLong1 = 953&
            Case "kappa": xLong1 = 954&
            Case "lambda": xLong1 = 955&
            Case "mu": xLong1 = 956&
            Case "nu": xLong1 = 957&
            Case "xi": xLong1 = 958&
            Case "omicron": xLong1 = 959&
            Case "pi": xLong1 = 960&
            Case "rho": xLong1 = 961&
            Case "sigmaf": xLong1 = 962&
            Case "sigma": xLong1 = 963&
            Case "tau": xLong1 = 964&
            Case "upsilon": xLong1 = 965&
            Case "phi": xLong1 = 966&
            Case "chi": xLong1 = 967&
            Case "psi": xLong1 = 968&
            Case "omega": xLong1 = 969&
            Case "thetasym": xLong1 = 977&
            Case "upsih": xLong1 = 978&
            Case "piv": xLong1 = 982&
            
            Case "ensp": xLong1 = 8194&
            Case "emsp": xLong1 = 8195&
            Case "thinsp": xLong1 = 8201&
            Case "zwnj": xLong1 = 8204&
            Case "zwj": xLong1 = 8205&
            Case "lrm": xLong1 = 8206&
            Case "rlm": xLong1 = 8207&
            
            'Case "mdash": xLong1 = 8210&
            'Case "ndash": xLong1 = 8211&
            
            Case "lsquo": xLong1 = 8216&
            Case "rsquo": xLong1 = 8217&
            Case "sbquo": xLong1 = 8218&
            
            Case "ldquo": xLong1 = 8220&
            Case "rdquo": xLong1 = 8221&
            Case "bdquo": xLong1 = 8222&
            Case "dagger": xLong1 = 8224&
            Case "Dagger": xLong1 = 8225&
            Case "bull": xLong1 = 8226&
            
            Case "hellip": xLong1 = 8230&
            Case "permil": xLong1 = 8240&
            Case "prime": xLong1 = 8242&
            Case "Prime": xLong1 = 8243&
            Case "lsaquo": xLong1 = 8249&
            Case "rsaquo": xLong1 = 8250&
            Case "oline": xLong1 = 8254&
'                Case "frasl": xLong1 = 8260&
            Case "euro": xLong1 = 8364&
            Case "image": xLong1 = 8465&
            Case "weierp": xLong1 = 8472&
            Case "real": xLong1 = 8476&
            Case "trade": xLong1 = 8482&
            Case "alefsym": xLong1 = 8501&
            Case "larr": xLong1 = 8592&
            Case "uarr": xLong1 = 8593&
            Case "rarr": xLong1 = 8594&
            Case "darr": xLong1 = 8595&
            Case "harr": xLong1 = 8596&
            Case "carr": xLong1 = 8629&
            Case "lArr": xLong1 = 8656&
            Case "uArr": xLong1 = 8657&
            Case "rArr": xLong1 = 8658&
            Case "dArr": xLong1 = 8659&
            Case "hArr": xLong1 = 8660&
            
            Case "forall": xLong1 = 8704&
            Case "part": xLong1 = 8706&
            Case "exist": xLong1 = 8707&
            Case "empty": xLong1 = 8709&
            Case "nabla": xLong1 = 8711&
            Case "isin": xLong1 = 8712&
            Case "notin": xLong1 = 8713&
            Case "ni": xLong1 = 8715&
            Case "prod": xLong1 = 8719&
            Case "sum": xLong1 = 8721&
            Case "minus": xLong1 = 8722&
            Case "lowast": xLong1 = 8727&
            Case "radic": xLong1 = 8730&
            Case "prop": xLong1 = 8733&
            Case "infin": xLong1 = 8734&
            Case "ang": xLong1 = 8736&
            Case "and": xLong1 = 8743&
            Case "or": xLong1 = 8744&
            Case "cap": xLong1 = 8745&
            Case "cup": xLong1 = 8746&
            Case "int": xLong1 = 8747&
            Case "there4": xLong1 = 8756&
            Case "sim": xLong1 = 8764&
            Case "cong": xLong1 = 8773&
            Case "asymp": xLong1 = 8776&
            Case "ne": xLong1 = 8800&
            Case "equiv": xLong1 = 8801&
            Case "le": xLong1 = 8804&
            Case "ge": xLong1 = 8805&
            Case "sub": xLong1 = 8834&
            Case "sup": xLong1 = 8835&
            Case "nsub": xLong1 = 8836&
            Case "sube": xLong1 = 8838&
            Case "supe": xLong1 = 8839&
            Case "oplus": xLong1 = 8853&
            Case "otimes": xLong1 = 8855&
            Case "perp": xLong1 = 8869&
            '''' wrong / reused Case "or": xLong1 = 8870&: Stop
            Case "sdot": xLong1 = 8901&
            Case "lceil": xLong1 = 8968&
            Case "rceil": xLong1 = 8969&
            Case "lfloor": xLong1 = 8970&
            Case "rfloor": xLong1 = 8971&
            Case "lang": xLong1 = 9001&
            Case "rang": xLong1 = 9002&
            Case "loz": xLong1 = 9674&
            Case "spades": xLong1 = 9824&
            Case "clubs": xLong1 = 9827&
            Case "hearts": xLong1 = 9829&
            Case "diams": xLong1 = 9830&
            
            Case Else
              GoTo NoGood
            End Select
          End If
'MaybeGood:
        If xLong1 < 32& Or xLong1 > &HFFFF& Then 'Or xLong1 > 126& Then
          If xLong1 = 9& Then
            GoTo GoodAnsi
            Else
            GoTo NoGood
            End If
          ElseIf Not Asc(ChrW(xLong1)) = xLong1 Then
          If IsUnicode Then
            UnHTML = UnHTML + Left(OrigText, xType - 1&) + ChrW(xLong1)
            'ElseIf Not xLong1 = 63& Then
            'UnHTML = UnHTML + Left(OrigText, xtype - 1&) + Chr(xLong1)
            Else
            GoTo NoGood
            End If
          Else
GoodAnsi:
          UnHTML = UnHTML + Left(OrigText, xType - 1&) + Chr(xLong1)
          End If
EndNoGood:
        OrigText = Mid(OrigText, xLong2 + 1&)
        End If
      End If
    Loop
  End Function
