Reputation: 962
I have been working with some code for a while and literally, all of the sudden it broke on me. Here is the error message I'm getting:
Run-time error '-2147467259 (80004005)'
Automation error
Unspecified error
the line of code is specifically when instantiating an InternetExporer object, except I have done nothing to change the code. It just stopped working. What could be the issue?
This has happened before and I corrected it by explicitly calling the library (MSHTML for a HTMLBsaeObject before), except I'm using just an Object when naming the 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
And the setup sub is this:
set iEx = CreateObject("InternetExplorer.Application")
fundToResarch = LCase(InputBox("Please Enter a Fund"))
Upvotes: 4
Views: 10991
Reputation: 19406
For others who end up here with the same error...
This can also be caused by referencing the Document
object property in an InternetExplorer
object after quitting and setting it to nothing. Note that this is not what is happening in the question. I was able to replicate the error with code similar to this:
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
Upvotes: 0
Reputation: 76
I've had a similar problem getting the 'Automation Error' creating an instance of InternetExplorer within a function that is called multiple times. It works fine to start, but after a number of calls will crash with the automation error. I discovered that I had multiple IE processes in memory, which means that setting objIE = Nothing
is insufficient to remove the process from memory. The solution is to call the 'Quit' method before setting objIE to Nothing.
That is:
objIE.Quit
'Put in a brief pause
set objIE = Nothing
Upvotes: 6