![]() |
Macro to Exit Worksheet when vbNo selected
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 |
Macro to Exit Worksheet when vbNo selected
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] On Thu, 4 Feb 2010 13:18:05 -0800, Craig wrote: 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 |
Macro to Exit Worksheet when vbNo selected
Thanks Chip....perfect result
"Chip Pearson" wrote: 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] On Thu, 4 Feb 2010 13:18:05 -0800, Craig wrote: 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 . |
All times are GMT +1. The time now is 10:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com