ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to Close Workbook Without Save Any Changes Made (https://www.excelbanter.com/excel-programming/430536-macro-close-workbook-without-save-any-changes-made.html)

Tyven Bong

Macro to Close Workbook Without Save Any Changes Made
 

How to make macro to close a workbook without save any changes that made
before the function CLOSE.


joel

Macro to Close Workbook Without Save Any Changes Made
 

first you can open the workbook in readonly mode to make sure no changes are
made to the workbook. Second when you save the workbook use

set bk = workbooks.open(filename:="book1.xls")

'your code here


bk.close savechanges:=False


"Tyven Bong" wrote:

How to make macro to close a workbook without save any changes that made
before the function CLOSE.


AltaEgo

Macro to Close Workbook Without Save Any Changes Made
 

From VBA help:

Remarks
Closing a workbook from Visual Basic doesn't run any Auto_Close macros in
the workbook. Use the RunAutoMacros method to run the auto close macros.

Example
This example closes Book1.xls and discards any changes that have been made
to it.

Workbooks("BOOK1.XLS").Close SaveChanges:=False





--
Steve

"Tyven Bong" <Tyven wrote in message
...
How to make macro to close a workbook without save any changes that made
before the function CLOSE.


AltaEgo

Macro to Close Workbook Without Save Any Changes Made
 

Or kill the lot

Sub QitNoSave()

Application.DisplayAlerts = False
Application.Quit 'closes Excel

End Sub

--
Steve

"AltaEgo" <Somewhere@NotHere wrote in message
...
From VBA help:

Remarks
Closing a workbook from Visual Basic doesn't run any Auto_Close macros in
the workbook. Use the RunAutoMacros method to run the auto close macros.

Example
This example closes Book1.xls and discards any changes that have been made
to it.

Workbooks("BOOK1.XLS").Close SaveChanges:=False





--
Steve

"Tyven Bong" <Tyven wrote in message
...
How to make macro to close a workbook without save any changes that made
before the function CLOSE.


Patrick Molloy

Macro to Close Workbook Without Save Any Changes Made
 

the application asks if you want to save if there have been any changes.

WB.Close False

is the easiest way to overcome this - where wb is the workbook obkect set to
the workbook we're dealing with.
Also , we could clear the dirty flag which tells excel whether the sheets
have changed or not in the ThisWorkbook's before close event. A value of
False would trigger the application alert to save.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub









"Tyven Bong" <Tyven wrote in message
...
How to make macro to close a workbook without save any changes that made
before the function CLOSE.



All times are GMT +1. The time now is 11:30 PM.

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