ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing Workbook without Saving (https://www.excelbanter.com/excel-programming/285056-closing-workbook-without-saving.html)

Chris Gorham[_3_]

Closing Workbook without Saving
 
Hi..

I'm attempting to write some code that will simply prevent
a workbook from saving changes and close (without any
display alerts) when the "X" is clicked.

Tried this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Close SaveChanges:=False

End Sub

however this results in Excel crashing...you can't select
a cell in the underlying workook that becomes the active
once this file closes. If you attempt to select another
sheet in it - crash..!!

Any help appreciated - I run Excel 2000

Rgds

Chris

No Name

Closing Workbook without Saving
 
Here you go, try this:

Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Saved = True
ThisWorkbook.Close

End Sub

-----Original Message-----
Hi..

I'm attempting to write some code that will simply

prevent
a workbook from saving changes and close (without any
display alerts) when the "X" is clicked.

Tried this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Close SaveChanges:=False

End Sub

however this results in Excel crashing...you can't select
a cell in the underlying workook that becomes the active
once this file closes. If you attempt to select another
sheet in it - crash..!!

Any help appreciated - I run Excel 2000

Rgds

Chris
.


Bill Manville

Closing Workbook without Saving
 
Chris Gorham wrote:
I'm attempting to write some code that will simply prevent
a workbook from saving changes and close (without any
display alerts) when the "X" is clicked.

Tried this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Close SaveChanges:=False

End Sub


Try

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Saved = True

End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com