这里有VBA
的第一次计时器:)
我在Excel中使用脚本将html标签显示为html(而不是纯文本)。脚本效果很好。但是,我想知道是否可以运行此脚本的“ reverse
”版本以将数据显示为显示html标签的纯文本。如果有可能,我将如何处理?感谢您的任何帮助!
脚本为:
Sub DisplayHTMLContentProperly()
Dim rng As Range
Dim row As Range
Dim cell As Range
Dim Ie As Object
Set Ie = CreateObject("InternetExplorer.Application")
Ie.Visible = True 'to be tested
Dim DataObj As MSForms.DataObject ' for clipboard
Set DataObj = New MSForms.DataObject
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
Set rng = Range("c2:c169")
For Each row In rng.Rows
For Each cell In row.Cells
Application.CutCopyMode = False
DataObj.GetFromClipboard
myString = " "
DataObj.SetText " "
If Not IsEmpty(cell) Then
With Ie
.Visible = True
.Navigate "about:blank"
While .Busy Or .ReadyState < 4: DoEvents: Wend
.Document.body.InnerHTML = cell 'update to the cell that contains HTML you want converted
.ExecWB 17, 0 'Select all contents in browser
.ExecWB 12, 2 'Copy them
'get data from clipboard (due to copy method above) and paste it into the cell
DataObj.GetFromClipboard
myString = DataObj.GetText(1)
'MsgBox myString - to debug
cell = myString
'delete anything from the clipboard
DataObj.Clear
Application.CutCopyMode = False
DataObj.SetText " "
End With
End If
'Do Something
Set HTML = Nothing
Application.Wait (Now + 0.000000011574 * 1200)
Next cell
Next row
Ie.Quit
Set Ie = Nothing
Application.CutCopyMode = False
MsgBox "I am now done with proper formatting of HTML column."
'move to see just summary page
Sheets("Summary").Activate
End Sub
答案 0 :(得分:1)
不,您不能,您将不得不编写第二个过程来完成相反的操作。反向过程将是完全不同的逻辑。
这不可能是自动的,因为某些功能可以颠倒而某些则不能。
例如,假设一个Sum
函数将1+2+3
与之相加,结果为6
,但由于该结果之前的信息不正确,因此该结果无法还原为1+2+3
在6
中显示。 6
也可以是4+2