Closing


Closing the Active Workbook

Application.ActiveWorkbook.Close SaveChanges:=False, _ 
                                 Filename:="", _
                                 RouteWorkbook:=False
ActiveWorkbook.Close

The SaveChanges argument is ignored if the workbook appears in another open window.
If you are trying to save a new workbook that has not yet been saved then you can use the Filename argument to specify the location and filename of the saved workbook.


If changes have been made to the workbook then the following line will prompt the user to save these changes.

ActiveWorkbook.Close 

ThisWorkbook.Close 
Workbooks("Book2.xls").Close
Workbooks(1).Close

Have the changes been saved ?

You can use the Saved property of a workbook to determine if any changes have not been saved.

If Application.ActiveWorkbook.Saved = True Then 
   Application.ActiveWorkbook.Close
Else
   Call Msgbox("changes not saved")
End If

Closing all Workbooks without saving

This method has no arguments.

Application.Workbooks.Close SaveChanges:=False 

Close without a prompt

You can change the Saved property of the workbook to True and Excel will think that there are no changes to be saved.

ActiveWorkbook.Saved = True 

Closing the Active Workbook

Application.ActiveWorkbook.Close SaveChanges:=False, _ 
                                 Filename:="", _
                                 RouteWorkbook:=False
ActiveWorkbook.Close

The SaveChanges argument is ignored of the workbook appears in another open window.
If you are trying to save a new workbook that has not yet been saved then you can use the Filename argument to specify the location and filename of the saved workbook.


ThisWorkbook.Close 
Workbooks("Book2.xls").Close
Workbooks(1).Close

Have the changes been saved

You can use the Saved property of a workbook to determine if any changes have not been saved.

If Application.ActiveWorkbook.Saved = True Then 
   Application.ActiveWorkbook.Close
Else
   Call Msgbox("changes not saved")
End If

Closing all Workbooks without saving

This method has no arguments.

Application.Workbooks.Close 

Closing a workbook automatically after 10 minutes

ActiveWorkbook.Close Savechanges:=False 

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext