Save reminder when closing a file

M

matthew77

We have an excel sheet we use to keep track of our purchase order
numbers. One of our users inputted several entries and then forgot to
save them. We want to avoid this situation but do not want to enable
autosave.

My question is a short one.

Is it possible to create a custom message, warning users to save this
sheet before exiting?


Any help or suggestions would be greatly appreciated.
 
R

Richard

Hi

I am a little confused because I thought Excel
automatically asked whether you wished to save the file
if it had changed. However you could write a simple macro
as below and call it Auto_Close. This will then run when
the user closes the file.

Regards

Richard

Sub Auto_Close()

ActiveWorkbook.Save

End Sub
 
D

Don Guillett

Or in the ThisWorkbook module use the before close event

Richard said:
Hi

I am a little confused because I thought Excel
automatically asked whether you wished to save the file
if it had changed. However you could write a simple macro
as below and call it Auto_Close. This will then run when
the user closes the file.

Regards

Richard

Sub Auto_Close()

ActiveWorkbook.Save

End Sub

-----Original Message-----
We have an excel sheet we use to keep track of our purchase order
numbers. One of our users inputted several entries and then forgot to
save them. We want to avoid this situation but do not want to enable
autosave.

My question is a short one.

Is it possible to create a custom message, warning users to save this
sheet before exiting?


Any help or suggestions would be greatly appreciated.



------------------------------------------------
[/url]
~~ View and post usenet messages directly from http://www.ExcelForum.com/

.
 
O

Otto Moehrbach

Matthew
There is a Workbook_BeforeClose event that Excel recognizes. This macro
is triggered by the Close command. You can insert VBA code to check if the
file has been saved. If it has, the code allows the file to close. If the
file has not been saved, the code would save the file, then allow the close
to occur.
You can change the code to check if the file has been saved, and if it
hasn't, bring up a message box that asks the user to save the file before
closing. The code would then cancel the close command and return the file
to the user.
The first macro is:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Saved = False Then
ThisWorkbook.Save
ThisWorkbook.Saved = True
End If
End Sub

The second is:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Saved = False Then
MsgBox "Please save this file before closing."
Cancel = True
End If
End Sub
 
Top