function myFunction() {
var spreadsheetId = "1kCUuu-BdcChTzUAQN5zk-FDQQV4RT8_R2czXYEq3LLQ"; // Please set the source Spreadsheet ID.
var destFolderId = "1-Br5Rdctt5Qy-0L7oE5B-JLLk6jmfCLE"; // Please set the destination folder ID.
// Copy each sheet in the source Spreadsheet by removing the formulas as the temporal sheets.
var ss = SpreadsheetApp.openById(spreadsheetId);
var tempSheets = ss.getSheets().map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
// Copy the source Spreadsheet.
var destination = ss.copy(ss.getName() + " - " + new Date().toLocaleString());
// Delete the temporal sheets in the source Spreadsheet.
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
// Delete the original sheets from the copied Spreadsheet and rename the copied sheets.
destination.getSheets().forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
// Move file to the destination folder.
var file = DriveApp.getFileById(destination.getId());
DriveApp.getFolderById(destFolderId).addFile(file);
file.getParents().next().removeFile(file);
var date = Utilities.formatDate(new Date(),"GMT","dd-MMMM-yyyy")
var message = {
bcc: "",
subject: "VB | Stocks & Dispatch Report as on " + date,
body: "Hi Team,\n\nPlease find attached the VB | Stocks & Dispatch Report " + date + "\n\nRegards,\nRoshan Kumar",
name: "Roshan Kumar",
attachments: [SpreadsheetApp.openById("1kCUuu-BdcChTzUAQN5zk-FDQQV4RT8_R2czXYEq3LLQ.xlsx")]
}
MailApp.sendEmail(message);
}