作者:张嫱的小屋_133 | 来源:互联网 | 2023-06-01 16:51
我有一个宏,可将带有HTML标记的单元格转换为简单文本。但是我需要在一定范围内奔跑。我尝试使用该范围,但出现错误。另外,我尝试使用activecell
,但无法使其在范围内运行。
工作表如下所示:
'
' HTML Macro
'
' Keyboard Shortcut: Ctrl+Shift+H
'
Dim Ie As Object
Set Ie = CreateObject("InternetExplorer.Application")
With Ie
.Visible = False
.Navigate "about:blank"
.document.body.InnerHTML = Sheets("Planilha").Range("C2").Value
'update to the cell that contains HTML you want converted
.ExecWB 17,0
'Select all contents in browser
.ExecWB 12,2
'Copy them
activeSheet.Paste Destination:=Sheets("Planilha").Range("D2")
'update to the cell you want converted HTML pasted in
.Quit
End With
End Sub
我相信你想要这样的东西。
Dim Ie As Object
Set Ie = CreateObject("InternetExplorer.Application")
Dim columnWithHTML As Integer
Dim yourAmountOfRows As Integer
columnWithHTML = 1
yourAmountOfRows = 140
Ie.Navigate "about:blank"
Dim i As Integer
For i = 1 To yourAmountOfRows
Ie.document.body.InnerHTML = Cells(i,columnWithHTML).Value2
'paste the text near HTML column
Cells(i,columnWithHTML + 1).Value = Ie.document.body.InnerText
Next
Ie.Quit
Set Ie = Nothing