Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Quiting Gracefully!

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Quiting Gracefully!

Hi Kevin

Don't. People quit wizards for a reason. If you, as a developer, really
believe that all changes are for the better, then save by code without
annoying the user. If not then trust their decisions.

HTH. Best wishes Harald

"Kevin" skrev i melding
...
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Quiting Gracefully!

Thanks for the help!
-----Original 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
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Quiting Gracefully!

Hi Harald,

May be I shouldnt have responded in light of my knowing not much. (dont know
what and how of Forms etc).

People quit wizards for a reason.

In a code (I know and use only simple IF, For etc) I have, I fear that
people might click on the close button by mistake and might lose the
important or laborious changes they have done. Hence to tread a middle path
between "changes are for the better, then save by code" and "If not then
trust their decisions." I use the close event with cancel as boolean so that
if the user clicks on close by mistake and if they think the changes are
legitimate then they may save and not exit out of the workbook. But suppose
the changes were not legitimate and then they may temporarily save it (lets
say in a temp folder) and then delete it. Is my logic correct?

Regards,
Hari
India

"Harald Staff" wrote in message
...
Hi Kevin

Don't. People quit wizards for a reason. If you, as a developer, really
believe that all changes are for the better, then save by code without
annoying the user. If not then trust their decisions.

HTH. Best wishes Harald

"Kevin" skrev i melding
...
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.







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Quiting Gracefully!

Hi Hari

No criticism intended. Your code is ok and your logic is fine. But Excel
herself will stop and ask "do you want to save changes ? (yes / no /
cancel)" if the workbook is dirty (unsaved) upon close. Which in theory
should deal with all your concerns on this.

I believe users should always have an emergency exit out of any application
or situation; properly marked, safe, friendly and understandable.

In the initial post Kevin says "They will enter date, then save the
information and quit". They will usually not. Many will open the file
because they opened the wrong one, others because they thought this was what
they needed but it's obviously not, still others will want to quit unsaved
because they want to do this later instead, it's too much of a job to do it
properly. Then we, developers, tell them "You are not allowed to leave this
room until you finish the job", or "I replaced the original data with what
you wrote anyway", or, preferrably, "Ok, nothing saved, welcome back when
you're ready".

My logic may not be correct either, but worst case scenarios are helpful to
me when I design user interfaces :-)

Best wishes Harald

"Hari" skrev i melding
...
May be I shouldnt have responded in light of my knowing not much. (dont

know
what and how of Forms etc).
People quit wizards for a reason.

In a code (I know and use only simple IF, For etc) I have, I fear that
people might click on the close button by mistake and might lose the
important or laborious changes they have done. Hence to tread a middle

path
between "changes are for the better, then save by code" and "If not then
trust their decisions." I use the close event with cancel as boolean so

that
if the user clicks on close by mistake and if they think the changes are
legitimate then they may save and not exit out of the workbook. But

suppose
the changes were not legitimate and then they may temporarily save it

(lets
say in a temp folder) and then delete it. Is my logic correct?

Regards,
Hari
India

"Harald Staff" wrote in message
...
Hi Kevin

Don't. People quit wizards for a reason. If you, as a developer, really
believe that all changes are for the better, then save by code without
annoying the user. If not then trust their decisions.

HTH. Best wishes Harald

"Kevin" skrev i melding
...
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.







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
Quiting Excel Michael Wise Excel Programming 4 March 4th 04 03:36 PM


All times are GMT +1. The time now is 05:33 AM.

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"