Fix Excel VBA Automation Error When Creating Internet Explorer
Question details
Fix an Excel VBA automation error that occurs after repeatedly creating Internet Explorer instances.

- Product
- Microsoft Excel VBA and Internet Explorer
- Device & OS
- not provided
- Scenario
- A macro repeatedly calls CreateObject("InternetExplorer.Application") to automate browser tasks.
- Observed behavior
- Run-time error -2147467259 (80004005) occurs after repeated calls, potentially because browser instances have not been properly closed.
In Excel, open the VBA editor with Alt+F11 and locate the procedure that creates the Internet Explorer object. Check whether the object is local or shared across procedures so cleanup happens only after all browser work is complete.
Quit each Internet Explorer instance before releasing it
Use this approach when repeated browser creation leaves instances running and eventually triggers the automation error.
Setting an object variable to Nothing releases the VBA reference but does not necessarily close the browser process. Call Quit after the browser work is finished, then release the reference.
DoEvents lets Windows process pending events, but it does not guarantee that the browser process has fully exited.
In the VBA editor, find Set ie = CreateObject("InternetExplorer.Application") and identify the work performed before the next loop iteration.
In the same procedure, use a cleanup block for both normal completion and errors. For example: Sub UseBrowser() Dim ie As Object On Error GoTo CleanUp Set ie = CreateObject("InternetExplorer.Application") ' Perform browser work here before cleanup. CleanUp: If Err.Number <> 0 Then Debug.Print Err.Number, Err.Description On Error Resume Next If Not ie Is Nothing Then ie.Quit Set ie = Nothing DoEvents On Error GoTo 0 End Sub
Run the calling macro from Excel or press F5 in the VBA editor. Check the Immediate window with Ctrl+G for any errors printed by the cleanup block.

Replace Internet Explorer automation where possible
Use a supported approach if Internet Explorer automation is unavailable or cleanup does not resolve the error.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and compatibility with common Microsoft Office formats, making it easy to move everyday spreadsheet work. It does not fix Excel's Internet Explorer automation error, and macro support may vary.

Frequently Asked Questions
Why does the automation error appear only after many iterations?
Repeatedly creating browser instances without closing them can consume system resources. In the VBA procedure, call ie.Quit after each instance's work is complete, then use Set ie = Nothing.
Is Set ie = Nothing enough to close Internet Explorer?
No. It releases the VBA reference but may leave the browser process running. Call ie.Quit first when the object was successfully created.
Where should I put DoEvents?
Place DoEvents after the cleanup calls if Windows needs an opportunity to process pending events before the next iteration. It does not guarantee that the process has fully exited.
Can I use Internet Explorer automation on every Windows system?
No. Internet Explorer is retired, and automation component availability depends on the environment. Consider an HTTP request or service API for data retrieval, or a supported browser automation tool for browser interaction.




