Closing Workbook without Saving

  • Thread starter Thread starter Chris Gorham
  • Start date Start date
C

Chris Gorham

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
 
Here you go, try this:

Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Saved = True
ThisWorkbook.Close

End Sub
 
Chris said:
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
 
Back
Top