带有标签的HTML文本,用于在Excel单元格中格式化文本

有没有办法采用HTML并将其导入到excel中,以便将其格式化为富文本格式(最好使用VBA)?基本上,当我粘贴到Excel单元格时,我希望将其更改为:


<html><p>This is a test. Will this text be <b>bold</b> or <i>italic</i></p></html>

到这个:


这是一个测验。该文字是粗体还是斜体


慕的地8271018
浏览 1422回答 3
3回答

收到一只叮咚

是的,这是可能的:)实际上,让Internet Explorer为您完成肮脏的工作;)经过测试我的假设我假设html文本在Sheet1的单元格A1中。您也可以改用变量。如果您的列中充满了html值,则只需将以下代码放入循环中码Sub Sample()&nbsp; &nbsp; Dim Ie As Object&nbsp; &nbsp; Set Ie = CreateObject("InternetExplorer.Application")&nbsp; &nbsp; With Ie&nbsp; &nbsp; &nbsp; &nbsp; .Visible = False&nbsp; &nbsp; &nbsp; &nbsp; .Navigate "about:blank"&nbsp; &nbsp; &nbsp; &nbsp; .document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value&nbsp; &nbsp; &nbsp; &nbsp; .document.body.createtextrange.execCommand "Copy"&nbsp; &nbsp; &nbsp; &nbsp; ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")&nbsp; &nbsp; &nbsp; &nbsp; .Quit&nbsp; &nbsp; End WithEnd Sub快照
打开App,查看更多内容
随时随地看视频慕课网APP