Hi all! I've been using the code below successfully numerous times, however periodically I am getting automation errors (breaks @ red bold below). I have searched all over and tried creating the IE window using "InternetExplorer", "InternetExplorerMedium", and "CreateObject" (as can be seen in my code). Over the last few hours, each of them have been successful at one point or another.
Now I again have the automation error, and none of the three options are working. I know that I can reboot my computer, and restart my application and it will work, but I'd like to figure out a true solution. I would really appreciate someone's help.
Also you might notice that I am parcing the entire data table from the IE session (successfully in an alternate code block using "instr" searching for 6 to 10 character strings), but I would love to know a smarter way to do it. If someone could point me to a good source of learning how to pinpoint information from webpages, that would be great.
The full error is:
Run-time error '-2147467259 (80004005)':
Automation error
Unspecified error
Now I again have the automation error, and none of the three options are working. I know that I can reboot my computer, and restart my application and it will work, but I'd like to figure out a true solution. I would really appreciate someone's help.
Also you might notice that I am parcing the entire data table from the IE session (successfully in an alternate code block using "instr" searching for 6 to 10 character strings), but I would love to know a smarter way to do it. If someone could point me to a good source of learning how to pinpoint information from webpages, that would be great.
The full error is:
Run-time error '-2147467259 (80004005)':
Automation error
Unspecified error
Code:
Sub Search_Link(sURL As String)
Dim IE As InternetExplorer
'Dim IE As InternetExplorerMedium
'Dim IE As Object ' IE.Application
Dim HTMLdoc As HTMLDocument
Dim downloadLink As HTMLAnchorElement
Dim i As Long
Dim xURL As String
'enable cancel interrupt
'Application.EnableCancelKey = xlErrorHandler
'On Error GoTo ErrHandler
'choose the data page
DATA.Activate
Range("a1000000").End(xlUp).Select
'setup internet explorer session
[B][COLOR="#FF0000"]Set IE = New InternetExplorer[/COLOR][/B]
'Set IE = New InternetExplorerMedium
'Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = False 'true
.navigate sURL 'CHANGE THIS
While .Busy Or .readyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set HTMLdoc = .document
End With
Set downloadLink = Nothing
xDuplicates = 0
i = 0
While i < HTMLdoc.Links.Length And downloadLink Is Nothing
'get the link
xURL = HTMLdoc.Links(i)
'put the link at the bottom of the URLs
If Right(xURL, 5) <> ".html" Then GoTo SkipURL
'search for duplicate link and skip if found
For r1 = 2 To Range("a1000000").End(xlUp).Row
If Range("a1").Offset(r1 - 1, 0) = xURL Then
' MsgBox ("Skipped url due to match. <" & xURL & ">")
xDuplicates = xDuplicates + 1
GoTo SkipURL
End If
Next
'place the link
Range("a1000000").End(xlUp).Offset(1, 0) = xURL
'force window to scroll
scrl = 20
If Range("a1000000").End(xlUp).Offset(1, 0).Row > scrl Then ActiveWindow.ScrollRow = Range("a1000000").End(xlUp).Offset(1, 0).Row - scrl
'allow system to check for the escape key pressed
' Call Sleep(100)
DoEvents
SkipURL:
i = i + 1
Wend
'close the window (unless specified to leave initial search windows open)
If vsParams.Offset(6, 1) = "No" Then IE.Quit 'jr
Exit Sub
ErrHandler:
'this section is for user interrupted action
If Err.Number = 18 Then
q = MsgBox("Cancel button pressed." & vbNewLine & vbNewLine & _
"Press [YES] to cancel" & vbNewLine & _
"Press [NO] to continue", vbYesNo)
If q = vbYes Then
'message for aborting the program
MsgBox ("Program ended at your request. If available, you can resume where you left off by re-running the program and selecting the option to resume where you left off.")
'set cancellation flag and exit
xCancel = True
Exit Sub
Else
xCancel = False
Resume
End If
Else
xCancel = True
MsgBox ("An unspecified error occurred, program is halting. Please try again. Contact admin if error persists.")
End If
End Sub
Last edited: