我正在尝试学习如何使用Excel VBA从HTML解析数据。所以我发现一个在线的例子工作得很好,但是当我在C上将URL地址从www.yahoo.com
更改为本地HTML文件时,它给出了错误,即方法'忙'对象'IwebBrowser2'失败。代码是:
Sub GetBodyText()
Dim URL As String
Dim Data As String
URL = "file:///C:/test.html"
Dim ie As Object
Dim ieDoc As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate URL
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
Set ieDoc = ie.Document
Data = ieDoc.body.innerText
'Split Data into separate lines
'or just use Range("A1")=data
Dim myarray As Variant
myarray = Split(Data, vbCrLf)
For i = 0 To UBound(myarray)
'Start writing in cell A1
Cells(i + 1, 1) = myarray(i)
Next
ie.Quit
Set ie = Nothing
Set ieDoc = Nothing
End Sub
答案 0 :(得分:0)
对于IE,只需使用:
URL = "c:\test.html"