|  

» Close a workbook using VBA in Microsoft Excel

VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
If you just want to close a workbook without the user being prompted for any confirmations
about saving the workbook you can simply do this :
ActiveWorkbook.Close False 
' closes the active workbook without saving any changes

ActiveWorkbook.Close True 
' closes the active workbook and saves any changes

ActiveWorkbook.Close 
' closes the active workbook and lets the user decide if 
' changes are to be saved or not



Rate This Tip
12 34 5
Rating: 4.04     Views: 372912
What if..
Norman Dolph  Posted on: 31-12-1969
No workbook is currently active? attempting to close it raises error. How do I detect IF any Workbook is active?
thanks!
RE: What if..
Ole P. Erlandsen  Posted on: 31-12-1969
This might help you:

If ActiveWorkbook Is Nothing Then Exit Sub
' exits the procedure if no workbook is active
thanks
nedolph  Posted on: 31-12-1969
Worked Perfectly
Worked like a charm!
James  Posted on: 31-12-1969
Thank you!
Name
Comment Title
Comments