I have created a simple emailing script for a google sheet. I need it to attach the PDF of the active file, but only 3 sheets (the 3 unhidden sheets). I have tried several things but nothing seems to work, I am honestly not an expert in Google script so I may be missing something obvious. Following is my code:
function sendEmails() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Email');
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = row[2];
var file= SpreadsheetApp.getActive();
MailApp.sendEmail(emailAddress, subject, message,{cc:"[email protected]",attachments:[file.getAs(MimeType.PDF)]});
}
}
What it does is attach the whole spreadsheet as a PDF, which doesn't help me because there are a lot of hidden sheets that I don't need in the PDF. Please help me!! Thanks!