I'm looking to modify this function so I don't actually need to click a Download Now link. I'd just like the script to download the sheet automatically. Appreciate any help. Thank you.
function copySheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = ss.getSheetByName("Road MT");
ss.rename(first.getRange(2, 14).getValue());
// this would change the name to whatever is in Row 2, col 14
var myValue =
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("N2")
.getValue();
var copiedSpreadSheet =
SpreadsheetApp.getActiveSpreadsheet().copy(myValue);
var ssID = SpreadsheetApp.getActive().getId();
var URL = 'https://docs.google.com/spreadsheets/d/'+ssID+'/export?
format=xlsx';
// Display a modal dialog box with download link.
var htmlOutput = HtmlService
.createHtmlOutput('<a href="'+URL+'">Download Now</a>')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(300)
.setHeight(40);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Download XLS');
}