Save reminder when closing a file

  • Thread starter Thread starter matthew77
  • Start date Start date
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.
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top