Prisoner 13
Prisoner 13

Reputation: 83

Can't insert sheet

I get the error message: "Specified sheet must be part of the spreadsheet". I assume the "specified sheet" is the sourceSheet... but who knows. What is this trying to tell me? Better yet, how do I fix it? I want to insert a sheet from spreadsheet "File1", into spreadsheet "File2".

Thank you

function copyTemplate() {

  var targetID="0Atn-Fxxxxt5YdF9VVxxxxxxxlZlVmeXoxxxzJuQ3c";

  // The code below will duplicate the sheet named "CellData" and insert it after 
  // the 1st sheet and call it "CellData"

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourceSheet = ss.getSheetByName("CellData");

  var targetFile=SpreadsheetApp.openById(targetID);  

  targetFile.insertSheet("CellData", 1, {template:sourceSheet});   

}

Upvotes: 0

Views: 841

Answers (1)

Bryan P
Bryan P

Reputation: 5051

function copyTemplate() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName('CellData')
  .copyTo(SpreadsheetApp.openById('0Atn-Fxxxxt5YdF9VVxxxxxxxlZlVmeXoxxxzJuQ3c'));
}

Upvotes: 1

Related Questions