Home » excel » VBScript: wait for Excel MsgBox, Click OK

VBScript: wait for Excel MsgBox, Click OK

Posted by: admin May 14, 2020 Leave a comment


I’ve written a VBScript that automates a load of processing of Excel workbooks.

For some of these workbooks, a MsgBox is triggered when they are opened. This message box is interrupting the automation.

Is there a way to listen for this MsgBox in a VBScript and “click” OK when it pops up?

How to&Answers:

Try to use this wrapper:

Application.DisplayAlerts = False
Application.Workbooks.Open ([your code])
Application.DisplayAlerts = True

This will suppress any warnings on opening, e.g. compatibility issues, etc.


In case MsgBox is generated from workbook code, try to use this:

Application.AutomationSecurity = msoAutomationSecurityForceDisable

In case Late Binding is used, this will work:

Application.AutomationSecurity = 3

Read more: http://support.microsoft.com/kb/886633