嘿,我的VBA代码收到“自动化错误”:
Set Doc = IE.document
当我调试时,我得到以上作为罪魁祸首,当我将鼠标悬停在Doc上为空时,并且IE.document引发自动化错误
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim IE As New InternetExplorer
IE.Visible = True
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim Np As String
For line = 2 To lp
ipp = Worksheets("sheet1").Cells(line, 1).Value
If ipp <> "" Then
IE.navigate ipp
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Np = Doc.getElementsByName("TITLE")(0).innerText
End If
IE.Quit
Next line
End Sub
[无论何时加载新页面,都需要刷新对新加载的文档的引用:
Set Doc = IE.document
... [在Do
循环之后]