如何替换excel文件中的所有html元素



我想知道如何在不命名所有html元素的情况下替换excel文件中的所有html元素。

此时此刻,我使用的宏将CCD_;未指定";,CCD_ 2&";,等等,但我必须一直添加新的值。

有更快的路吗?

MSHTML可以做到这一点:

With CreateObject("htmlfile")
.Open
.write "<p> fish <em>&amp;</em> chips &hellip;"
.Close
MsgBox .body.outerText '// fish & chips …
End With

示例

Sub MyCode()
'// put some html in A1
Range("A1").Value = "<p> fish <em>&amp;</em> chips &hellip;"

'// put the html as text in B1
Range("B1").Value = getPlainTextFromHTML(Range("A1").Value)
End Sub
Function getPlainTextFromHTML(html As String)
With CreateObject("htmlfile")
.Open
.write html
.Close
getPlainTextFromHTML = .body.outerText
End With
End Function

最新更新