VBA random automation error in CreateObject("InternetExplorer.Application")

499 Views Asked by At

So...

I searched through the forum, and really found a lot of threads with awesome suggestions, but none of them works (Example

Thing is my code randomly breaks on Set ie = CreateObject("InternetExplorer.Application"). After resuming code it is always continuing without a problem. Error msg is: Run-time error '-2147467259 (80004005)' Automation error Unspecified error

After each iteration I do ie.quit and set ie = nothing and additionally I checked and clear processes, just in case if internetexplorer would pile up and suffocate my computer in the background.

Something like:

If CheckIFRunning("INTERNET EXPLORER.EXE") = True Or CheckIFRunning("IEXPLORE.EXE") = True Then oProc.Terminate

And like many suggested I tried Set ie = New InternetExplorerMedium but with no luck.

I added application.wait as I thought maybe there is a split second where IE is still not close and I'm already starting a new instance but that didn't help as well.

I can add a code, but it is extremely long and my only problem is on CreateObject.

I would like to at least resume execution even if for some reason really there is a problem with creating object (and yes, I've tried on error resume next).

1

There are 1 best solutions below

3
xShen On

Try this, hope it will help you .

replace

Set ie = CreateObject("InternetExplorer.Application")

with

    ' Ignore the error 
    On Error Resume Next
    '  if IE already open then try to get the object 
    Set ie = GetObject(, "InternetExplorer.Application")
    ' Check is there error after the get object 
    If Err.Number <> 0 Then
      ' if an error happen then try to create new IE  
        Err.Clear
       Set ie = CreateObject("InternetExplorer.Application")
    End If
   ' Turn Error reporting back on  
    On Error GoTo 0