Reputation: 11
I have google sheet template made for a local business. The template will be used in a store day to day. I need a Script that duplicates the sheet each day automatically so we don't manually have to. I want the sheets to stay in the same spread sheet, but each tab is a new day. The tab i want to be the date of the day. I know i can use a trigger to auto generate but I don't know how to copy the exact template or change the name of the tab autmatically
Upvotes: 1
Views: 756
Reputation: 185
Try something like this:
function duplicateSpreadSheets() {
var sheetName, sheet, destination, currentDate;
sheetName = "Name of sheet goes here";
sheet = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName(sheetName);
destination = SpreadsheetApp.openById("Spreadsheet ID goes here (the first string of nubmers and letters in the url)");
sheet = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName("Copy of " + sheetName)
.activate();
currentDate = new Date(Date.now()); //change the format of the date to what you want, DD/MM/YYYY etc.
SpreadsheetApp.getActiveSpreadsheet()
.renameActiveSheet(currentDate)
}
Go to Resources > All your triggers.. and make this function trigger once per day.
Also keep in mind that Google Spreadsheets has a hard limit of 200 sheets per workbook (or used to, not sure if this has changed) so after 200 days this will stop working.
Upvotes: -1