Office Script to open new worksheet and name with current date

dgold

New Member
Joined
Feb 3, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have tried to use the following script from an old message on this board in Office 365 to open a new worksheet and name it with the current date. This code only opens a new sheet with the name "Sheetx" (x is increasing numbers). I would also like to be able to open the new sheet from a template and delete/hide the previous day's worksheet. Here is the code I am starting with:

function main(workbook: ExcelScript.Workbook) {
// Add a new worksheet
let sheet1 = workbook.addWorksheet();
let tracks = workbook.getWorksheet("Tracks");
// Paste range at Sheet1!A1 from Tracks!1:1048576
sheet1.getRange("A1")
.copyFrom(tracks.getRange("1:1048576"), ExcelScript.RangeCopyType.all, false, false);
// Rename worksheet to "November 5th"
let denumire: Date = new Date();
sheet1.setName(denumire.toISOString().slice(0, 10));

}
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,242
Messages
6,123,830
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top