Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何替换excel文件中的所有html元素_Html_Vba - Fatal编程技术网

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

如何替换excel文件中的所有html元素,html,vba,Html,Vba,我想知道如何替换excel文件中的所有html元素而不命名它们 此时,我正在使用一个宏来替换ê带有“Ê”和“带有“”,等等。但我必须一直添加新值 有没有更快的方法?MSHTML可以做到这一点: With CreateObject("htmlfile") .Open .write "<p> fish <em>&amp;</em> chips &hellip;" .Close

我想知道如何替换excel文件中的所有html元素而不命名它们

此时,我正在使用一个宏来替换
ê
带有“Ê”和“
带有“”,等等。但我必须一直添加新值

有没有更快的方法?

MSHTML可以做到这一点:

With CreateObject("htmlfile")
    .Open
    .write "<p> fish <em>&amp;</em> chips &hellip;"
    .Close
    MsgBox .body.outerText '// fish & chips …
End With
与CreateObject(“htmlfile”)
打开
.写下“fish&;chips&hellip;”
.结束
MsgBox.body.outerText'//鱼和薯条…
以
范例

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
Sub MyCode()
“//在A1中放入一些html
范围(“A1”).Value=“fish&;chips&hellip;”
'//将html作为文本放在B1中
范围(“B1”).Value=getPlainTextFromHTML(范围(“A1”).Value)
端接头
函数getPlainTextFromHTML(html为字符串)
使用CreateObject(“htmlfile”)
打开
.编写html
.结束
getPlainTextFromHTML=.body.outerText
以
端函数
MSHTML可以做到这一点:

With CreateObject("htmlfile")
    .Open
    .write "<p> fish <em>&amp;</em> chips &hellip;"
    .Close
    MsgBox .body.outerText '// fish & chips …
End With
与CreateObject(“htmlfile”)
打开
.写下“fish&;chips&hellip;”
.结束
MsgBox.body.outerText'//鱼和薯条…
以
范例

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
Sub MyCode()
“//在A1中放入一些html
范围(“A1”).Value=“fish&;chips&hellip;”
'//将html作为文本放在B1中
范围(“B1”).Value=getPlainTextFromHTML(范围(“A1”).Value)
端接头
函数getPlainTextFromHTML(html为字符串)
使用CreateObject(“htmlfile”)
打开
.编写html
.结束
getPlainTextFromHTML=.body.outerText
以
端函数

Hoe我可以将其集成到我的代码中吗?或者我需要一个单独的子对象?将其封装在上述函数中。好的,但是如果我想对列中的所有行执行此操作,我尝试设置thisWbs=ActiveWorkbook.ActiveSheet LastRow=thisWbs.Range(“F”&ActiveSheet.rows.Count.End(xlUp)。Row Set Rng=thisWbs.Range(“F2:F”&LastRow)Range(“F2:F”&LastRow)。Value=getPlainTextFromHTML(Range(“F2:F”&LastRow).Value)但我认为有些地方不对劲。我可以将其集成到我的代码中吗?或者我需要一个单独的子对象?将其封装在上述函数中。好的,但是如果我想对列中的所有行执行此操作,我尝试设置thisWbs=ActiveWorkbook.ActiveSheet LastRow=thisWbs.Range(“F”&ActiveSheet.rows.Count.End(xlUp)。Row Set Rng=thisWbs.Range(“F2:F”&LastRow)Range(“F2:F”&LastRow)。Value=getPlainTextFromHTML(Range(“F2:F”&LastRow).Value)但我认为有些错误Ok,它适用于特定单元格,但我如何才能选择整个列(比如D)并在同一列中返回结果?请记住将您的代码添加到问题中,以使其对其他读者更有用。我如何替换所有工作表中的字符,而不仅仅是一个单元格?Ok,它适用于特定单元格,但如何选择整个列(比如D)并在同一列中返回结果?请记住将代码添加到问题中,以使其对其他读者更有用。如何替换所有工作表中的字符,而不仅仅是一个单元格?