VBScript: wait for Excel MsgBox, Click OK

Griffin Source

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?

excelvbscriptautomationmsgbox

Answers

answered 6 years ago Maks Gordeev #1

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.

UPDATE:

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

comments powered by Disqus