Creating a Warning message


Posted by Susan K on January 12, 2001 11:57 AM

I have created a macro for our daily sales sheet that needs to be run at the beginning of each week.

I would like to include a Warning message box that will ask the user if they really meant to activate the command button -- a Yes-Cancel option. What should the VBA code look like?



Posted by Tim Francis-Wright on January 12, 2001 2:22 PM

Try the following in your existing sub
(you can leave out the title line, of course);
I assumed that hitting No wil just stop things,
but you might have other plans.


ans = MsgBox(prompt:="Do you really want to do this?", _
Buttons:=vbYesNo + vbExclamation, _
Title:="Thanks, Mr. Excel!")

if ans = vbNo then Exit Sub ' vbNo = 7, vbYes = 6

Good luck!