我想知道如何使用VBA脚本将带有html标签的整列单元格转换为格式化文本(基于这些标签) .
我能够根据以前的列表转换一个单元格:HTML Text with tags to formatted text in an Excel cell
使用以下内容:
Sub Sample()
Dim Ie As Object
Set Ie = CreateObject("InternetExplorer.Application")
With Ie
.Visible = False
.Navigate "about:blank"
.document.body.InnerHTML = Sheets("Sheet1").Range("A1").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("Sheet1").Range("B1")
'update to cell you want converted HTML pasted in
.Quit
End With
End Sub
但这只会转换列中的第一个单元格 . (在上面的示例中,我手动键入A2和B2以执行第二个单元格) . 如果这是一个天真的问题,我很抱歉,但我是VBA的新手 . 我试过使用循环并玩范围,但没有成功 .
2 回答
您的代码仅适用于第一行,因为您只获取并设置第一行:
要为所有行应用代码,必须在循环内执行它 .
所以你的代码变成:
请检查: