Move Worksheet.(Microsoft Excel Office Scripts)

Japanese version.

Introduces how to move a worksheet using Office scripts.


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

workbook.getWorksheet("Moving sheet name").setPosition(Destination location);

The position to be moved is a sequential number starting from 0 (first).

Move to the top (leftmost)

If 0 is specified, it moves to the beginning.

// Move to the top
workbook.getWorksheet("Moving sheet name").setPosition(0);

Move to the end (rightmost)

The next designation moves to the bottom.

// Move to the end
workbook.getWorksheet("Moving sheet name").setPosition(workbook.getWorksheets.length - 1);

Moves to the front or back of the specified worksheet

To move to the front or back of a given worksheet, do the following

let targetSheet = workbook.getWorksheet("Moving sheet name");
let baseSheet = workbook.getWorksheet("Reference sheet name");
let before:boolean = True if moving before the reference sheet; false if moving after the reference sheet;

let targrtPosition = targetSheet.getPosition();
let basePosition = baseSheet.getPosition();
let offset: number;

  if (basePosition < targrtPosition) {
    offset = 0;
  else {
    offset = -1;
  if (basePosition > targrtPosition) {
    offset = 0;
  else {
    offset = 1;

  basePosition + offset

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