Nicholas
Nicholas

Reputation: 2668

How do I automatically press OK button for the message box in Excel VBA?

I am using Application.run to call a macro in another workbook written by my colleague that has something like this in the middle,

resp = MsgBox("Message goes here...", vbOKCancel)

How do I press OK automatically, basically suppressing the message box? I used Application.DisplayAlerts = False at the top of my sub and also put Application.SendKeys ("~") right below Application.run, neither works.

Upvotes: 3

Views: 6044

Answers (1)

Ashish Baboo
Ashish Baboo

Reputation: 154

If you need to press the OK button of message box automatically that means you want to execute the whole program regardless of output of message-box. In this case you can just remove the command of message-box display and use the variable in the rest of program. So that neither you will get message-box nor you will be needed to press OK button.

Upvotes: 1

Related Questions