Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default 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

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeating a Macro For Each Selected Worksheet carl Excel Worksheet Functions 0 January 11th 06 10:07 PM
[Fwd: Run macro on exit worksheet/workbook] toontje Excel Discussion (Misc queries) 1 August 5th 05 03:49 AM
Run macro on exit worksheet/workbook toontje Excel Worksheet Functions 3 August 2nd 05 10:15 PM
How to run a macro when a worksheet is selected cpmittal Excel Worksheet Functions 2 July 27th 05 11:57 AM
Automatically Run a macro when a worksheet is selected Rob Bovey Excel Programming 2 October 19th 03 10:00 PM


All times are GMT +1. The time now is 11:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"