Here’s an example of an OfficeScript that creates a new sheet in an existing workbook:
function main(workbook: ExcelScript.Workbook) { // Create a new sheet let newSheet = workbook.addWorksheet(); // Rename the new sheet newSheet.setName("NewSheet"); }
To use this OfficeScript, follow these steps:
- Open Excel Online or Excel for the web.
- Open an existing workbook or create a new workbook.
- Click on the “Automate” tab in the ribbon.
- Click on the “Script Lab” button.
- In the Script Lab pane, create a new script or open an existing one.
- Replace the default code in the script editor with the code provided above.
- Click the “Run” button to execute the script.
This script adds a new sheet to the existing workbook and renames it as “NewSheet”. You can modify the name of the sheet by changing the argument of the setName
function.
Please note that OfficeScripts are currently only supported in Excel for the web and Excel Online. They are not available in the desktop version of Excel.