Macro to Exit Worksheet when vbNo selected

  • Thread starter Thread starter Craig
  • Start date Start date
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
 
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]
 
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
.
 
Back
Top