Activate a worksheet
This article explains how to use Office Scripts to make a specific worksheet active, with sample code.
Method to use
Section titled “Method to use”Use the activate method of the ExcelScript.Worksheet object.
ExcelScript.Worksheet.activate(): void;It has no arguments and no return value. When you run it, the target worksheet becomes active in Excel.
Sample code
Section titled “Sample code”This sample code specifies a sheet name and makes the target sheet active.
If the target sheet isn’t found, it throws an error.
function main(workbook: ExcelScript.Workbook) { /** Target sheet name */ const sheetname = 'Sheet1';
/** Target worksheet */ const sheet = workbook.getWorksheet(sheetname);
if (!sheet) { throw `There is no worksheet named ${sheetname}`; }
// Activate the worksheet sheet.activate();}Get a worksheetExplains how to get a specific worksheet in Office Scripts, with sample code.