Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用Internet Explorer时出现Excel VBA错误462_Html_Excel_Vba_Internet Explorer_Navigation - Fatal编程技术网

Html 使用Internet Explorer时出现Excel VBA错误462

Html 使用Internet Explorer时出现Excel VBA错误462,html,excel,vba,internet-explorer,navigation,Html,Excel,Vba,Internet Explorer,Navigation,我有这个功能: Sub CreateDatabase() Dim ieNewPage As InternetExplorer, TableRows As Object, TableRow As Object Dim TableRowsSpecificOwner As Object, TableRowSpecificOwner As Object, TagNeeded As Object Set TableRows = GetData() Set ieNewPage

我有这个功能:

Sub CreateDatabase()
    Dim ieNewPage As InternetExplorer, TableRows As Object, TableRow As Object
    Dim TableRowsSpecificOwner As Object, TableRowSpecificOwner As Object, TagNeeded As Object
    Set TableRows = GetData()
    Set ieNewPage = New InternetExplorer
    For Each TableRow In TableRows
        ieNewPage.navigate CStr(TableRow.href)
        Do While ieNewPage.ReadyState <> 4
            DoEvents
        Loop
        ieNewPage.Visible = True
        Set TableRowsSpecificOwner = ieNewPage.document.querySelectorAll("tr[class='puce_texte']")
        For Each TableRowSpecificOwner In TableRowsSpecificOwner
            If Excel.Application.IfError(Excel.Application.Search("France", TableRowSpecificOwner.innerText), -1) > 0 Then
                    Debug.Print TableRow.innerText
                    Debug.Print TableRowSpecificOwner.getElementsByTagName("a")(1).innerText
            End If
        Next
        Excel.Application.Wait (Now + TimeValue("0:00:02"))
    Next
End Sub

我该怎么解决这个问题

有一篇关于此错误的文章:,您可以检查它。错误的原因是:

Visual Basic已建立对Excel的引用,因为有一行代码调用Excel对象、方法或属性,而不使用Excel对象变量限定元素。在结束程序之前,Visual Basic不会释放此引用。当代码多次运行时,此错误引用会干扰自动化代码

我认为发生错误是因为您没有第二次调用
ieNewPage的
Set
。您可以尝试将
Set ieNewPage=New InternetExplorer
放入如下循环:

...    
Set TableRows = GetData()    
For Each TableRow In TableRows
    Set ieNewPage = New InternetExplorer
    ieNewPage.navigate CStr(TableRow.href)
    ...
Next
...

(TableRows包含一个内有href的标记和一个我也需要的textpart)了解运行函数“GetData()”或函数代码本身后接收到的对象类型可能很有用。@ZygD TableRows中的对象示例如下:
Run
typename(TableRows)
并告诉我们您得到的类型名称。@ZygD我得到:
disphtmlementcollection
...    
Set TableRows = GetData()    
For Each TableRow In TableRows
    Set ieNewPage = New InternetExplorer
    ieNewPage.navigate CStr(TableRow.href)
    ...
Next
...