Automation errors using internet explorer

jryan15

Board Regular
Joined
Jan 27, 2005
Messages
168
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


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:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
As expected, I logged off and logged back on, and it's working again. Would really like to figure this out for future events though.
 
Upvote 0

Forum statistics

Threads
1,215,669
Messages
6,126,120
Members
449,293
Latest member
yallaire64

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top