Reputation: 1
I am very new to app script and I have found a few codes that either make a copy, rename or save in the correct location but I have not found one that does all three. Here is the code I found that does part of what I am looking for.
I have tried this script and I want to add the naming variable to be dependent on a cell in the main tab.
function saveAsSpreadsheet(){ var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange('cklist!A1:B3'); sheet.setNamedRange('buildingNameAddress', range);
var TestRange = sheet.getRangeByName('buildingNameAddress').getValues();
Logger.log(TestRange); var destFolder = DriveApp.getFolderById("xxxxx"); //I add the corect folder ID here
DriveApp.getFileById(sheet.getId()).makeCopy("TestScope PDFs", destFolder); }
Upvotes: 0
Views: 30
Reputation: 41
modify the code to work with your files actual id
function saveAsSpreadsheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var nameSheet = sheet.getSheetByName('cklist');
var nameRange = nameSheet.getRange('A1');
var newName = nameRange.getValue();
var destFolder = DriveApp.getFolderById('xxxxx');
var newSpreadsheet = sheet.copy('Copy of ' + sheet.getName());
newSpreadsheet.setName(newName);
var file = DriveApp.getFileById(newSpreadsheet.getId());
destFolder.addFile(file);
DriveApp.getRootFolder().removeFile(file);
Logger.log('Spreadsheet copied, renamed to "' + newName + '", and moved to the specified folder.');
}
Upvotes: 0