Reputation: 568
I am using
Set NewBook = Workbooks.Add
to create a new workbook. I need to refer to this workbook without saving it. So I am using workbook index number to refer to the new workbook, is there a way to retrieve the index number of the last workbook open/created (the highest index number)?
Upvotes: 1
Views: 507
Reputation: 23283
For the highest index number, you can just use Worksheets.Count. That'll return how many sheets you have, thus telling you the highest index.
Upvotes: 1
Reputation: 3290
You can use this to get the last workbook
Set LastWorkbook = Workbooks(Workbooks.Count)
BUT if you already have the NewBook
variable, can't you just use that? The reason i say that is because relying on a workbook
's index may not give consistent results.
Upvotes: 3