Count number of opened Excel Workbooks
10,171
Solution 1
Just solved!!! I just needed to get the instance of workbooks correctly:
Set objExcel = GetObject(, "Excel.Application")
Set WB = objExcel.ActiveWorkbook
Set WBS = objExcel.Workbooks
WScript.Echo WBS.Count
Solution 2
Why the VBA tag if you are using VBScript?
To get the number of Workbooks in an Excel instance simply use this VBA code:
MsgBox Workbooks.Count
To get the number of instances of Excel open using VBA then refer to this article:
http://excelribbon.tips.net/T009452_Finding_Other_Instances_of_Excel_in_a_Macro.html
Author by
Asier Pomposo
Updated on June 13, 2022Comments
-
Asier Pomposo over 1 year
I need to know how many Excel files are opened, so in case there are more than two, I can close the last one. How can I get number the of opened files?? I have read Worksbooks.Count... but I´m not getting anything at all. I´m using vbscript code.
I have tried this... but just get the name of the file.
Set objExcel = GetObject(, "Excel.Application") Set WB = objExcel.ActiveWorkbook WScript.Echo "Hello" + WB.Name WScript.Echo "number of excel" + WB.Count