Hi there!
This is a great question - thanks so much for asking! Could you let me know if the following code works for your workbook?
function main(workbook: ExcelScript.Workbook) {
// Get all the worksheets in the workbook.
let sheets = workbook.getWorksheets();
// Get a list of all the worksheet names.
let names = sheets.map((sheet) => sheet.getName());
// Write in the console all the worksheet names and the total count.
console.log(names);
console.log(Total worksheets inside of this workbook: ${sheets.length}
);
// Set the tab color each worksheet to a random color
for (let sheet of sheets) {
// Generate a random color hex-code.
sheet.getFreezePanes()
.freezeAt(sheet.getRange("A1:A11"));
}
}
As an added note, I adapted most of this code from the "Iterating over collections" section of the Office Scripts documentation: https://learn.microsoft.com/en-us/office/dev/scripts/resources/excel-samples. I hope this helps!
-Nancy from the Office Scripts team
Attached is screen shot of worksheet names