I have been working on a script that allows me to modify a recently created spreadsheet.
Here’s what I want to do:
- Create new spreadsheet
- Copy a sheet from current spreadsheet into new spreadsheet
- Replace name of new sheet in new spreadsheet.
Here is the code that I have created but when I run it I am able to create the spreadsheet but the sheet from the original spreadsheet is not copied into the new spreadsheet.Basically I am able to create the spreadsheet but once created I am not able to write on the new one. Any ideas??”
function dashboards(){
//creates dashboards
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
ss1.setActiveSheet(ss1.getSheetByName("Sheet1"));
var ssNew = SpreadsheetApp.create("New spreadsheet").getId();
var ss2 = SpreadsheetApp.openById(ssNew).setActiveSpreadsheet;
ss1.copyTo(ssNew)
ssNew.renameActiveSheet("newsheet");;
}
Looks like you were pretty close, but I can’t follow along all the variable references. Here is re-written version that worked for me.
I think the main issue might be the hanging
setActiveSpreadsheetcall in line 6 that might have broken your variable assignments.Another key point to make is that you can get a reference to the sheet in the new spreadsheet back from the
copyTocall