Sub Test()
Dim Win As Window
For Each Win In Application.Windows
If Win.Visible = False And UCase(Win.Parent.Name) <> "PERSONAL.XLS" Then
Win.Parent.Close
End If
Next Win
End Sub
Example
This example closes Book1.xls and discards any changes that have been made to it.
Workbooks("BOOK1.XLS").Close SaveChanges:=False
This example closes all open workbooks. If there are changes in any open workbook, Microsoft Excel displays the appropriate prompts and dialog boxes for saving changes.
Workbooks.Close
Workbooks.Close SaveChanges:=False
and the quoted stringworkbooks.close
and got some 8000 finds. All the responses that I looked at had either workbooks or close, but none had the phrase "workbooks.close""workbooks.close"
Well I learned something . I did not think that it would work like that... though I would speculat ethat the parameters for closing an entire collection woul dbe different from the parameters to close a single workbook... hence the error.Hello hatman,
Thanks for your response.
I am developing some code that opens multiple workbooks and moves data between them. At the end of my code was the line:
Workbooks.Close
It did close them all.
However, due to the mere act of opening workbooks, and the fact that I made changes, caused Excel to prompt me if I wanted to save the changes. In this case I did not want to save anything, I was testing code and saving the results of my mistakes would cause serious problems. I wanted to just close all of them without changes and be done with it.
While writing this it ocuured to me, set the files to read only, suppress alerts, and maybe that would work. Just the same, there should be a way to do this deed directly. (I.e. some line of code that effectively says: "Excel, Close all of this crap, don't save anything, and don't prompt for anything.)