Internet Explorer对象Excel VBA中的自动化错误未指定错误

我一直在编写一些代码,从字面上来看,突然间它突然袭击了我。 这是我收到的错误消息:

Run-time error '-2147467259 (80004005)' Automation error Unspecified error 

该代码行是特别实例化一个InternetExporer对象,除了我没有做任何更改代码。 它刚刚停止工作。 可能是什么问题?

这发生之前,我纠正它通过显式调用库(MSHTML的HTMLBsaeObject之前),除了我只使用一个对象时命名variables

 Public Sub ValueLineResearch() setUp Dim myFund As String loginN = Sheets("Logins").Range("B2").Text pwStr = Sheets("Logins").Range("B3").Text 'Get the site iEx.Navigate "https://jump.valueline.com/login.aspx" iEx.Visible = True Call waitForIE 'Need to login now don't we iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_txtUserID").Value = loginN iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_txtUserPw").Value = pwStr iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_btnLogin").Click Call waitForIE Application.Wait DateAdd("s", 6, Now) iEx.Navigate "https://research.valueline.com/secure/research#sec=library" Call waitForIE For Each el1 In iEx.Document.getElementsByClassName("symbol-search textInput ui-autocomplete-input mod_search-symbols primary_symbol_search") el1.Value = fundToResearch Next Application.Wait DateAdd("s", 2, Now) iEx.Document.forms("quoteSearch").submit Call waitForIE Application.Wait DateAdd("s", 2, Now) iEx.Navigate "https://research.valueline.com/secure/research#list=recent&sec=company&sym=" & fundToResearch Call waitForIE 'store the Doc Set ieDoc = iEx.Document 'For linkItem = 0 To ieDoc.Links.Length - 1 ' 'Get the PDF ' If InStr(1, ieDoc.Links(linkItem).href, ".pdf", vbTextCompare) > 0 And InStr(1, ieDoc.Links(linkItem).href, "UserGuide", vbTextCompare) <= 0 Then ' ieDoc.Links(linkItem).Click ' iEx.Visible = True ' Exit For ' End If 'Next linkItem Set iEx = Nothing End Sub 

而设置子是这样的:

 set iEx = CreateObject("InternetExplorer.Application") fundToResarch = LCase(InputBox("Please Enter a Fund")) 

我有一个类似的问题得到的“自动化错误”创build一个被称为多次的函数内的InternetExplorer实例。 它可以正常工作,但是在多次调用之后会自动出现错误。 我发现我在内存中有多个IE进程,这意味着设置objIE = Nothing不足以从内存中删除进程。 解决方法是在将objIE设置为Nothing之前调用“退出”方法。

那是:

 objIE.Quit 'Put in a brief pause set objIE = Nothing 

对于其他人在这里结束了相同的错误…

这也可能是由于在退出InternetExplorer对象时引用Document对象属性并将其设置为空。 请注意,这不是问题中正在发生的事情。 我能够用类似这样的代码复制错误:

 Dim ie As New InternetExplorer ie.Visible = True ie.Navigate "google.com" ie.Quit Set ie = Nothing If ie.Document Is Nothing Then 'Error thrown here MsgBox "Can't get here" End If