打开网站时出现自动化错误

时间:2019-10-04 16:20:29

标签: vba

嘿,我的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

1 个答案:

答案 0 :(得分:1)

无论何时加载新页面,都需要刷新对新加载文档的引用:

Set Doc = IE.document

...在Do循环之后

相关问题