PDA

View Full Version : AUTOMATICALLY CLICK DEFAULT MESSAGE BOX



BBALLER8AND1
06-03-2010, 12:56 PM
I am trying to edit some vba code for excel. When I run the macro, about 20 different message boxes pop up during the 5 minutes that the macro takes to run through. I want to click the default response for each of these message boxes automatically so that the code can just run through without someone having to be there to click yes or ok every half a minute or so. Any ideas?

austenr
06-03-2010, 01:07 PM
You could use a timer I think to make them disappear after a certain time say 1 second. Don't have time to code it right now but I think it might work for you.

BBALLER8AND1
06-03-2010, 01:11 PM
Only problem is that I can't edit the original code to make the message boxes disappear. I am basically coding a macro that runs a different macro using many different values. So I am running that macros many times, and each time I just want to answer yes to a question. Thanks for the help

Paul_Hossler
06-03-2010, 06:14 PM
I use the Scripting Host Popup to do automatic closes (below) for my boxes or if they're system boxes, a lot of times Application.DisplayAlerts = False will work. You do need to remember to turn it back on

When all else fails, you might try .Sendkeys to put an "Enter" there to close it


Option Explicit

'MsgButton
' vbOKOnly
' vbOKCancel
' vbAbortRetryIgnore
' vbYesNoCancel
' vbYesNo
' vbRetryCancel
'MsgIcon
' vbInformation
' vbCritical
' vbQuestion
' vbExclamation
'MsgDefault
' vbDefaultButton1
' vbDefaultButton2
' vbDefaultButton3
'Response
' NoResponse = -1
' vbOK
' vbCancel
' vbAbort
' vbRetry
' vbIgnore
' vbYes
' vbNo
Sub Test()
Dim objShell As Object
Dim iAns As Long

iAns = CreateObject("WScript.Shell").Popup( _
"This is OK Only", 3, "Just wait until it's done", _
vbQuestion + vbOKOnly + vbDefaultButton1)

MsgBox iAns


iAns = CreateObject("WScript.Shell").Popup( _
"This is Yes and No", 9, "Click Yes or No", _
vbCritical + vbYesNo + vbDefaultButton2)
MsgBox iAns

Set objShell = Nothing
End Sub


Paul