Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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.

Reply
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
Close workbook without being prompted to save in VBA J Wait Excel Programming 5 December 19th 07 10:28 PM
Open New Workbook / Save and Close Current Workbook Joe K. Excel Programming 1 December 7th 07 08:04 PM
Save Changes Prompt before Close, when no changes were made [email protected] Excel Programming 1 September 21st 06 07:26 PM
Help on Workbook close and workbook save events Adam Harding Excel Programming 1 September 29th 05 04:12 PM
i made change in a current workbook and accidentally save it, can. angel Excel Discussion (Misc queries) 1 January 4th 05 01:11 AM


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

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

About Us

"It's about Microsoft Excel"