Duplicate current sheet using OfficeScripts

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:

  1. Open Excel Online or Excel for the web.
  2. Open an existing workbook.
  3. Click on the sheet that you want to copy.
  4. Click on the “Automate” tab in the ribbon.
  5. Click on the “Script Lab” button.
  6. In the Script Lab pane, create a new script or open an existing one.
  7. Replace the default code in the script editor with the code provided above.
  8. 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.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech