excel - “反向”在 Excel 中运行 VBA 脚本
问题描述
在这里的第一个计时器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
解决方案
不,你不能,你必须编写第二个程序来做相反的事情。相反的过程将是一个完全不同的逻辑。
这不可能是自动的,因为有些功能可以反转,有些则不能。
例如,想象一个对结果Sum
求和的函数,但这个结果无法恢复,因为关于它之前的信息不再存在于那个中。也可以是1+2+3
6
1+2+3
6
6
4+2
推荐阅读
- python - 尝试平均字典中每个键的值后无法正确绘制图表
- matlab - 如何在 Matlab 中正确继承 TCPIP 类?
- python - 在张量流中以另一个张量作为种子生成随机序列
- amazon-web-services - aws appsync 组合过滤器运算符
- python-3.x - 如何使用 Python 获取路透社网站的一个子版块(例如中东)的 20 多个新闻标题链接?
- mysql - 如何将数据插入中间表,这可以在单个 mysql 查询中完成吗?
- apache - 为什么我得到错误的文档根目录?
- mongodb - 如何在 MongoDB 中返回具有最新日期的元素
- android - 将数据导入 AlertDialog,同时避免“尝试在空对象引用上调用虚拟方法”
- git - 为什么 `git rev-parse HEAD^2` 不起作用?