VBA & Macro Problems

Fix Excel VBA Automation Error When Creating Internet Explorer

Huda QurayshiHuda Qurayshi Nov 20, 2026 868 views

Question details

Fix an Excel VBA automation error that occurs after repeatedly creating Internet Explorer instances.

Fix Excel VBA Automation Error When Creating Internet Explorer
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate the creation call

In the VBA editor, find Set ie = CreateObject("InternetExplorer.Application") and identify the work performed before the next loop iteration.

2
Add a cleanup block

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

3
Run the loop again

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.

Quit each Internet Explorer instance before releasing it
Finish browser work before quitting: Do not call Navigate or other browser methods after Quit. If navigation is asynchronous, wait for the required work to finish, with an appropriate timeout, before cleanup.
Free Microsoft Office alternative

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.

Open and edit Excel spreadsheet files, including XLSX and XLS formatsUse a familiar spreadsheet interface for everyday workbook tasksKeep working with spreadsheet data while planning a replacement for retired Internet Explorer automationUse a lightweight office suite with a free version
microsoft office alternative - wps office

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.