LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Exit Excel programmatically

I found my own solution that seems to work.
When data on the sheet has changed, the user is notified, in the beforeclose
event of the workbook, that changes were not saved. If they want to save
the data before leaving, I exit the beforeclose event. If they do not want
to save the changes, I set the "saved" property to "True" and let the
routine continue. If the user wanted to close the workbook, it closes, if
they wanted to Exit Excel, then it will exit.
Thanks to anyone who put any thought into this.

--
Bob Holmes MCNGP #31
"Bob Holmes" wrote in message
...
I hate to be a pest, but, I think I'm nearing completion of my project.
Since my workbook is being used as a data entry front-end, I do not want
Excel to ask the user about saving changes (to the workbook). In my code,

I
know if the user has saved his data to the database. If the user tries to
close or exit without having saved the data, I want to give him a chance

to
save it, then close or exit. This is the code I've tried and the results.
If someone can see that I'm doing something wrong, or, better yet, if

anyone
knows how to do this correctly, I would be greatly appreciate some

feedback.

In "ThisWorkbook"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim intResponse As Integer

intResponse = MsgBox("Data Not Saved, Quit anyway?", vbYesNoCancel, "Not
Saved")
If intResponse < vbYes Then
Cancel = True
Exit Sub
Else
'Prevents this event from being triggered a second time
Application.EnableEvents = False
'Don't display the save changes dialog
ThisWorkbook.Close savechanges:=False
Application.Quit
End If

This works the first time, but, if I open the workbook again, without

having
exited Excel, this code does not run and I get prompted by Excel about
saving changes. Also, if the user makes a change and then tries to exit
Excel, the workbook closes, but the application continues to run, forcing
them to click 'exit' again.
Thanks in advance for any help you can give.

--
Bob Holmes




 
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
Programmatically inserting a row with Excel 2003 stonequest Excel Programming 4 May 3rd 04 11:58 AM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM
Who can tell me how to programmatically insert an image into Excel by C#? syf Excel Programming 0 January 13th 04 10:29 AM
Subscribing programmatically from Excel via VBA John Noel Excel Programming 0 September 23rd 03 05:47 PM
Excel VBA Programmatically delete a form? Anthony Keefe Excel Programming 0 August 30th 03 10:03 PM


All times are GMT +1. The time now is 06:55 AM.

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

About Us

"It's about Microsoft Excel"