View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Hari[_3_] Hari[_3_] is offline
external usenet poster
 
Posts: 157
Default Quiting Gracefully!

Hi Kevin,

What about the following in this workbook code module?

Private Sub Workbook_beforeclose(Cancel As Boolean)
Application.ScreenUpdating = False

If ThisWorkbook.Saved = False Then

MsgBox "Please save the workbook before exiting"
Cancel = True

End If

End Sub

Regards,
Hari
India

"Kevin" wrote in message
...
How do I prevent someone from closing a workbook unless
changes have been saved. I want to force the user to save
a file and not allow them to exit unless the changes have
been saved.

I have an Excel Workbook that the user will open as a
template. They will enter date, then save the information
and quit. I am using forms to control the users interface
but if they close the form, they can click the X at the
top (or select Quit from the Menu) and exit, then click
cancel on the SaveAs dialog box and quit the application
without saving changes.

I use a Form to allow the user to enter a file name, then
place the file in a specified directory. This all works
fine, but if they simply close the form and then hit the X
at the top, they can quit the application without saving
changes. If I can force them to go back to the form where
they enter a file name, that would be prefered because I
can then place the file in a directory of my choosing.

Any ideas or help would be appreciated.

Kevin