Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default save on exit message box

Is their a way to display a message box, when the user click to exit
the worksheet using a macro?

The user will have 3 options Yes, No, Cancel.

How can I program this using VBA in Ms Excel XP?

------------------------------------------------

The code I use at the moment saves the worksheet without asking the
user:

Sub CloseSpreedsheet()
'Saves spreedsheet
ThisWorkbook.Saved = True
'Closes the application
Application.Quit
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default save on exit message box

Olly,

First of all, the line of code
ThisWorkbook.Saved = True
does NOT save the workbook. It tells Excel that the workbook does not need
to be saved, but does NOT actually save any changes.

Try something like the following:

Sub CloseSpreedsheet()
Dim Res As Long
Res = MsgBox("Do you want to save?", vbYesNoCancel)
Select Case Res
Case vbYes
ThisWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Exit Sub
End Select
Application.Quit
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Olly" wrote in message
om...
Is their a way to display a message box, when the user click to exit
the worksheet using a macro?

The user will have 3 options Yes, No, Cancel.

How can I program this using VBA in Ms Excel XP?

------------------------------------------------

The code I use at the moment saves the worksheet without asking the
user:

Sub CloseSpreedsheet()
'Saves spreedsheet
ThisWorkbook.Saved = True
'Closes the application
Application.Quit
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default save on exit message box

If you want to save the workbook automatically then the
code is
ThisWorkbook.Save

On Excel 97 at least, is the default to ask users if they
want to save changes before closing a workbook.

If you want to produce this message box yourself, you
could try

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Select Case MsgBox("Want to SAve", vbQuestion
+YesNoCancel)
Case vbYes
ThisWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Cancel = True
End Select
End Sub


libby

-----Original Message-----
Olly,

First of all, the line of code
ThisWorkbook.Saved = True
does NOT save the workbook. It tells Excel that the

workbook does not need
to be saved, but does NOT actually save any changes.

Try something like the following:

Sub CloseSpreedsheet()
Dim Res As Long
Res = MsgBox("Do you want to save?", vbYesNoCancel)
Select Case Res
Case vbYes
ThisWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Exit Sub
End Select
Application.Quit
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Olly" wrote in message
. com...
Is their a way to display a message box, when the user

click to exit
the worksheet using a macro?

The user will have 3 options Yes, No, Cancel.

How can I program this using VBA in Ms Excel XP?

------------------------------------------------

The code I use at the moment saves the worksheet

without asking the
user:

Sub CloseSpreedsheet()
'Saves spreedsheet
ThisWorkbook.Saved = True
'Closes the application
Application.Quit
End Sub



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default save on exit message box

Thanks that's what i needed

"Chip Pearson" wrote in message ...
Olly,

First of all, the line of code
ThisWorkbook.Saved = True
does NOT save the workbook. It tells Excel that the workbook does not need
to be saved, but does NOT actually save any changes.

Try something like the following:

Sub CloseSpreedsheet()
Dim Res As Long
Res = MsgBox("Do you want to save?", vbYesNoCancel)
Select Case Res
Case vbYes
ThisWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Exit Sub
End Select
Application.Quit
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

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
how do i get the option to save changes when i exit ceedee Excel Discussion (Misc queries) 2 September 19th 09 12:16 AM
Why does Excel ask to Save on Exit? JRSNHECI Excel Discussion (Misc queries) 5 December 18th 08 04:10 AM
Automatic Save and Exit duane Excel Discussion (Misc queries) 1 July 18th 06 10:32 AM
On Exit, always asked to save loveexcel Excel Worksheet Functions 3 June 29th 06 09:51 PM
Save & Exit Anthony Excel Worksheet Functions 1 February 12th 05 05:23 PM


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

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

About Us

"It's about Microsoft Excel"