I have this script to copy actual sheet as a new spreadsheet named with value from I2 Cell:
function CopySheet(){
var sheet = SpreadsheetApp.getActiveSheet(); // Get current active sheet.
var sheet_name = sheet.getRange("i2").getValue(); // Get the value of cell B1, used to name the new spreadsheet.
var folder = DriveApp.getFolderById("xxxxxxxxxxxxx"); // Get the ID of the folder where you will place a copy of the spreadsheet.
var newSS = SpreadsheetApp.create(sheet_name); // create new blank spreadsheet in a root folder
var asFile = DriveApp.getFileById(newSS.getId()); // get new spreadsheet as a file
folder.addFile(asFile); // add this file to destination folder
DriveApp.getRootFolder().removeFile(asFile); // remove a file from root folder
var copiedSheet = sheet.copyTo(newSS); // copy active sheet to new spreadsheet
copiedSheet.setName(sheet_name); // rename copied sheet
newSS.deleteSheet(newSS.getSheetByName('Sheet1')); // remove "Sheet1" sheet which was created by default in new spreadsheet
}
Script beautifully copy sheet as a new spreadsheet but there's ugly "Sheet1".
When script comes to line 15 : newSS.deleteSheet(newSS.getSheetByName('Sheet1'));
i get error: Exception: Argument nie może być zerowy: sheet (wiersz 15, plik „Kod”) - Argue cannot be zero: sheet(row 15, file "Kod").
Please for help.