我一直在处理一些代码并且字面意思,突然之间它突破了我。以下是我收到的错误消息:
Run-time error '-2147467259 (80004005)'
Automation error
Unspecified error
代码行特别是在实例化InternetExporer对象时,除了我没有做任何更改代码。它刚刚停止工作。可能是什么问题?
之前发生了这种情况,我通过显式调用库(之前是HTMLHTsaeObject的MSHTML)来纠正它,除了我在命名变量时只使用了一个Object
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"))
答案 0 :(得分:5)
我遇到了类似的问题,导致了“自动化错误”问题。在多次调用的函数中创建InternetExplorer的实例。它可以正常启动,但在多次调用后会因自动化错误而崩溃。我发现我在内存中有多个IE进程,这意味着设置objIE = Nothing
不足以从内存中删除进程。解决方案是打电话给退出&#39;退出&#39;将objIE设置为Nothing之前的方法。
那是:
objIE.Quit
'Put in a brief pause
set objIE = Nothing
答案 1 :(得分:0)
对于那些以同样的错误来到这里的人......
这也可能是由于在退出并将其设置为空后在Document
对象中引用InternetExplorer
对象属性引起的。请注意,这不是问题中发生的事情。我能够使用与此类似的代码复制错误:
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