Get sheets number function
This function — a mix of JavaScript & VBScript so it’s for Windows only — was written and tested in InDesign CC 2023 (18.4) and Excel 2019 on Windows 10. It opens an Excel workbook and returns the number of spreadsheets.
Thus we can know the number of available spreadsheets beforehand, say, to use it later in the ‘for’ loop.
Note: the only argument sent to the function is the excelFilePath — the path to the Excel file — it’s a Windows path where the backslashes should be escaped by backslashes. In other words, doubled.
Click here to download the function.