The below script has been working fine for multiple things but the letter returns as a PDF letter named "Site Utilities" this is the whole spreadsheet name.
I would like it to return tab/sheet name "Park Letter" instead. Even better would be a chosen name or a cell within the sheet.
function Email3() {
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
//var email = Session.getUser().getEmail();
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Park Letter").getRange("F20");
var emailAddress = emailRange.getValue();
var subject = "Coffee Morning";
var body = ("Attached is a letter about the up coming Coffee Morning. \n \nMany thanks, \n \nCoast and Country Parks");
var requestData = {"method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()}};
var shID = getSheetID("Park Letter") //Get Sheet ID of sheet name "Master"
var url = "https://docs.google.com/spreadsheets/d/"+ ssID + "/export?format=pdf&id="+ssID+"&gid="+shID;
var result = UrlFetchApp.fetch(url , requestData);
var contents = result.getContent();
MailApp.sendEmail (emailAddress, subject ,body, {attachments:[{fileName:sheetName+".pdf", content:contents, mimeType:"application//pdf"}]});
};
function getSheetID(name){
var ss = SpreadsheetApp.getActive().getSheetByName(name)
var sheetID = ss.getSheetId().toString()
return sheetID
}
I have looked at other examples where it states get sheet name rather than spreadsheet but this didn't seem to work.
I also saw an option for just changing the name "Get New Name". This made sense but I don't think I am putting the code within the right section.
About
I would like it to return tab/sheet name "Park Letter" instead.When I saw your showing script,
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();is used as the filename of PDF file atMailApp.sendEmail (emailAddress, subject ,body, {attachments:[{fileName:sheetName+".pdf", content:contents, mimeType:"application//pdf"}]});. If you want to use the value ofPark Letteras the filename of a PDF file, how about the following modification?By the way, I think that
application//pdfshould beapplication/pdf.From:
To:
or
By this modification, the filename of the PDF file is
Park Letter.pdf.About
Even better would be a chosen name or a cell within the sheet.If you want to use the filename from the cell value, how about the following modification? In this case, please replace
###to your sheet name. And, the value of cell "A1" is used as the filename. Please modify it to your actual situation.From:
To:
or
By this modification, the cell value of "A1" of the sheet "###" is used as the filename of the PDF file.
Added:
About your following new question.
If you want to use the values of
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("vicki working sheet").getRange("F20:F76")asbcc, how about the following modification?From:
To: