Copy Worksheet.(Microsoft Excel Office Scripts)

Japanese version.

Introduces how to copy a Worksheet using Office scripts.


The following syntax is used (Red text indicates variable parts).

workbook.getWorksheet("Worksheet name to copy").copy();

The added sheets can also be assigned to variables.

The sheet variables can be used to set values, etc.

variable name = workbook.getWorksheet("Worksheet name to copy").copy();

Parameters are optional, but can be specified for more detailed operations.


Additional copy Worksheet position (positionType)

Set valueDescription.
ExcelScript.WorksheetPositionType.afterCreates a copy sheet after the specified sheet.
The following parameters must be used to specify which sheet to create after.
ExcelScript.WorksheetPositionType.beforeCreates a copy sheet before the specified sheet.
The following parameters must be used to specify which sheet to create before.
ExcelScript.WorksheetPositionType.beginningCreate a copy sheet at the top.
ExcelScript.WorksheetPositionType.endCreate a copy sheet at the end.
ExcelScript.WorksheetPositionType.noneCreates a copy sheet at the beginning.
(Default value when omitted)
// Add to the top
workbook.getWorksheet("Worksheet name to copy").copy(ExcelScript.WorksheetPositionType.beginning);

// Add to the end
workbook.getWorksheet("Worksheet name to copy").copy(ExcelScript.WorksheetPositionType.end);

// Add to beginning (default value)
workbook.getWorksheet("Worksheet name to copy").copy(ExcelScript.WorksheetPositionType.none);

Reference Worksheet (relativeTo)

If "after" or "before" is specified for "positionType," the reference worksheet is also specified.

// 基準シートの前に追加
workbook.getWorksheet("Worksheet name to copy").copy(
  workbook.getWorksheet("Reference Worksheet Name")

// 基準シートの後ろに追加
workbook.getWorksheet("Worksheet name to copy").copy(
  workbook.getWorksheet("Reference Worksheet Name")

For those who want to learn Office script effectively

The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Excel Office Script to streamline your workflow.


Office Scripts Articles