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

Vba 打开网站时出现自动错误,vba,Vba,嘿,我的VBA代码出现自动错误: Set Doc = IE.document 当我调试时,我发现上面的错误是罪魁祸首,当我将鼠标移到Doc上时,Doc是空的,IE.document抛出了自动化错误 Application.ScreenUpdating = False Application.DisplayAlerts = False Dim IE As New InternetExplorer IE.Visible = True Dim Doc As HTM

嘿,我的VBA代码出现自动错误:

Set Doc = IE.document
当我调试时,我发现上面的错误是罪魁祸首,当我将鼠标移到Doc上时,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循环之后