Here’s an example of an OfficeScript that creates a copy of the current sheet in an existing workbook:
function main(workbook: ExcelScript.Workbook, sheetName: string) { // Get the active sheet let activeSheet = workbook.getWorksheet(sheetName); // Create a copy of the active sheet let newSheet = activeSheet.copy(); // Rename the new sheet newSheet.setName("Copy of " + sheetName); }
To use this OfficeScript, follow these steps:
- Open Excel Online or Excel for the web.
- Open an existing workbook.
- Click on the sheet that you want to copy.
- 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 creates a copy of the current active sheet in the workbook and renames it as “Copy of [sheetName]”. You need to provide the name of the sheet you want to copy as an argument when executing the script.
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.