How to Automate Internet Explorer Confirmation Dialogs with VBA
Question details
The user needs a way to programmatically interact with a 'Yes/No' confirmation dialog that appears after clicking a button on a webpage via VBA.

- Product
- VBA / Internet Explorer
- Device & OS
- not provided
- Scenario
- Running a VBA web scraping or automation script where a secondary pop-up blocks the execution flow.
- Observed behavior
- The VBA procedure cannot click the confirmation dialog using standard DOM methods, and the script hangs waiting for user input. Power Automate also fails to interact with the dialog.
Ensure your VBA editor is open and that your computer will remain untouched during script execution, as this workaround relies on the browser maintaining active window focus.
Use Application.SendKeys to Handle the Dialog
This workaround sends keyboard strokes directly to the active window to dismiss the dialog, bypassing the inability to target it via HTML elements.
Because confirmation dialogs are OS-level or browser-level modal windows, standard HTML Document Object Model (DOM) methods cannot interact with them. By ensuring the browser is the active window, you can simulate a keyboard 'Enter' press to accept the dialog.
In your VBA code, ensure the Internet Explorer object is visible and active by adding `ie.Visible = True` before triggering the button.
Click the webpage button using its actual HTML ID in the DOM, for example: `ie.document.getElementById("SubmitButton").Click`.
Add a short delay to allow the confirmation pop-up to fully render on the screen. Use `Application.Wait (Now + TimeValue("0:00:02"))`.
Execute `Application.SendKeys "{ENTER}"` to simulate pressing the Enter key, which typically triggers the default 'Yes' or 'OK' option on the confirmation pop-up.

Upgrade Your Spreadsheet Tasks with WPS Office
While Internet Explorer automation is now obsolete, modernizing your workflow is easier than ever with WPS Office. As a lightweight, feature-rich suite, it offers excellent support for advanced data processing, macros, and seamless compatibility with your existing files—all for free.

Frequently Asked Questions
Why can't standard VBA click the Yes/No confirmation dialog?
Standard VBA web automation interacts with the HTML Document Object Model (DOM). Confirmation dialogs are typically generated by the browser or operating system as modal pop-ups, existing outside the webpage's HTML structure, making them invisible to standard DOM targeting methods.
Is Application.SendKeys safe to use for automation?
While useful as a quick workaround, Application.SendKeys is generally considered unreliable. If a user clicks away or another background application steals focus while the script is running, the keystrokes will be sent to the wrong window, which could cause unintended actions on your PC.
Are there better alternatives to automating Internet Explorer?
Yes. Internet Explorer is obsolete and no longer supported by Microsoft. It is highly recommended to migrate your automation to modern tools. Excellent alternatives include Selenium Basic for VBA, Python (with Selenium or Playwright), or modernizing your flows using Microsoft Power Automate Desktop with supported browsers like Edge or Chrome.




