Macro to Exit Worksheet when vbNo selected

C

Craig

Hi,

I have a straightforward msgBox that starts when a worksheet is opened.
It has vbYesNo
Is there any code that I can put into or assign to the No buton that will
close the worksheet without saving anything, including the prompt for 'Do you
want to Save Changes' msg that normally comes up when closing.

Bottom line...if Yes, then we continue with input....if No then close (exit)
immediately

Thanks

Craig
 
C

Chip Pearson

The following code will open a Msgbox and if the user chooses No, the
workbook will close without saving any changes.

Dim Res As VbMsgBoxResult
Res = MsgBox("Your Message", vbYesNo)
If Res = vbNo Then
ThisWorkbook.Close savechanges:=False
End If


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 
C

Craig

Thanks Chip....perfect result

Chip Pearson said:
The following code will open a Msgbox and if the user chooses No, the
workbook will close without saving any changes.

Dim Res As VbMsgBoxResult
Res = MsgBox("Your Message", vbYesNo)
If Res = vbNo Then
ThisWorkbook.Close savechanges:=False
End If


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




Hi,

I have a straightforward msgBox that starts when a worksheet is opened.
It has vbYesNo
Is there any code that I can put into or assign to the No buton that will
close the worksheet without saving anything, including the prompt for 'Do you
want to Save Changes' msg that normally comes up when closing.

Bottom line...if Yes, then we continue with input....if No then close (exit)
immediately

Thanks

Craig
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top