我有这段代码可以识别活动标签
Sub Test()
Dim ieTab As SHDocVw.InternetExplorer
Dim shWin As SHDocVw.ShellWindows
Dim s As String
Set shWin = New SHDocVw.ShellWindows
For Each ieTab In shWin
s = ieTab.LocationURL
If s = "my criteria string" Then
'MsgBox "Page Found", 64
'Here I need to export the active tab to HTML file
Else
'Do Nothing
End If
Next ieTab
Set ieTab = Nothing
Set shWin = Nothing
End Sub
我需要知道如何将此活动标签导出到HTML文件 感谢高级帮助
答案 0 :(得分:0)
在IF语句之后,我使用这些行解决了问题
f = FreeFile()
Open ThisWorkbook.Path & "\LocalHTML.html" For Output As #f
Print #f, ieTab.document.body.innerHTML
Close #f
有一个新问题,就是使用其他代码@QHarr读取Unicode字符时,我没有得到正确的结果 如何使用ADODB写入导出的html?
我也尝试了这部分,并且遇到了同样的问题
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.CreateTextFile(ThisWorkbook.Path & "\LocalHTML.html", False, True) 'Unicode=True
myFile.WriteLine ieTab.document.body.innerHTML
myFile.Close
最后的解决方案 这是使我能够以正确方式导出到HTML的代码
Set fStream = New ADODB.Stream
With fStream
.Charset = "UTF-8"
.Open
.WriteText ieTab.document.body.innerHTML
.SaveToFile Environ("USERPROFILE") & "\Desktop\LocalHTML.html", 2
.Close
End With