Skip to main content

Activation

We explain how to use an Office Scripts to activate a specific worksheet in conjunction with a sample code.

Method to use

Excelscript.Worksheet Use the Active method provided in the object.

ExcelScript.Worksheet.activate(): void;

There is no argument or return value.By execution, the target worksheet becomes active.

Sample code

This is a sample code that specifies the sheet name and activates the target sheet.

If you can't find the target sheet, throw the 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 worksheets
sheet.active();
}