Excel VBA去除过滤HTML代码

  • A+

1.正则表达式

Function RemoveHTML( strText )
	Set regex = CreateObject("VBScript.RegExp")
	RegEx.Pattern = "<[^>]*>"
	RegEx.Global = True
	RemoveHTML = RegEx.Replace(strText, "")
End Function

2.自定义函数检测<>提取内容

Function RemoveHTML(strText)
    Dim nPos1
    Dim nPos2
    
    nPos1 = InStr(strText, "<")
    Do While nPos1 > 0
        nPos2 = InStr(nPos1 + 1, strText, ">")
        If nPos2 > 0 Then
            strText = Left(strText, nPos1 - 1) & Mid(strText, nPos2 + 1)
        Else
            Exit Do
        End If
        nPos1 = InStr(strText, "<")
    Loop
    
    RemoveHTML = strText
End Function
weinxin
独角兽驿站
公众号

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: