Do not propmt to save data on exit

  • Thread starter Glenn Rathke \(Soft Design Consulting\)
  • Start date
G

Glenn Rathke \(Soft Design Consulting\)

I'm reading/writing Excel data to SQL Server thru VBA. As such I do not
want to be prompted to save the data when closing down Excel. How can I do
this?
 
P

Paul Mathews

Hi Glenn, try this:

Application.DisplayAlerts = False
Workbooks("YourWorkbook.xls").Close
Application.DisplayAlerts = True

If you want to immediately close right out of Excel then replace the second
line with Application.Quit.
 
G

Glenn Rathke \(Soft Design Consulting\)

Thanks for the info but unfortunately it does not work or I am missing
something else.

If the user changes a cell in the spreadsheet, I do not want the message to
appear asking them if they want to save the file when closing the workbook.
Even with this code they user is prompted. Perhaps I implemented it
incorrectly, I placed it in the before close event.

Thanks
Glenn Rathke





"Glenn Rathke (Soft Design Consulting)"
 
G

Glenn Rathke \(Soft Design Consulting\)

This line of code does the trick, I put it in the BeforeClose event.

ThisWorkbook.Saved = True

It tells the workbook that the most recent copy of the data has been saved
(in actuality it has not) and that it is not dirty. Now when the close event
is fired, the data does not appear that it has been changed.

Glenn


"Glenn Rathke (Soft Design Consulting)"
Thanks for the info but unfortunately it does not work or I am missing
something else.

If the user changes a cell in the spreadsheet, I do not want the message
to appear asking them if they want to save the file when closing the
workbook. Even with this code they user is prompted. Perhaps I
implemented it incorrectly, I placed it in the before close event.

Thanks
Glenn Rathke





"Glenn Rathke (Soft Design Consulting)"
 
Top