[RESOLVED] Close Specific WorkBook - Excel VBA
I have two workbooks open (actually, they are two completely separate Excel Files - those are workbooks, right?) I want to close one of them but not both of them.
WorkBooks.Close Book2 gives me an error of "Wrong number of arguments or invalid property assignment"
I looked up Workbooks.Close and find that it does not have, or require, any arguements.....(which would make sense given the error), it just closes everything that is open.
As mentioned, I don't want both files to be closed, just one of them.
So, how would I do that?
Re: Close Specific WorkBook - Excel VBA
Quote:
Originally Posted by Hack
I have two workbooks open (actually, they are two completely separate Excel Files - those are workbooks, right?)
Correct.
Quote:
As mentioned, I don't want both files to be closed, just one of them.
So, how would I do that?
Use the Close method of the specific WorkBook object, rather than the WorkBooks collection, eg: Book2.Close
(if it has been changed since it was last saved, set the "SaveChanges" parameter to false, otherwise you will get a message asking if you want to save).
Re: Close Specific WorkBook - Excel VBA
Like Si mentioned, its a collection of workbooks so you can use the index as that is what it is puking about in the error.
Code:
Workbooks(2).Close SaveChanges:=False
Re: Close Specific WorkBook - Excel VBA
Quote:
Originally Posted by si_the_geek
Correct.
Use the Close method of the specific WorkBook object, rather than the WorkBooks collection, eg: Book2.Close
(if it has been changed since it was last saved, set the "SaveChanges" parameter to false, otherwise you will get a message asking if you want to save).
Yepper, that worked.
Quote:
Originally Posted by RobDog888
Like Si mentioned, its a collection of workbooks so you can use the index as that is what it is puking about in the error.
Code:
Workbooks(2).Close SaveChanges:=False
Where you been? :eek: