0
votes

Email the entire tab from the current sheet I have open.

I have already built a button and assigned a script to email, however I want a button that will send the current sheet that i have open to a set address. When I use the button I created it only sends an email, no attachment or no sheet.

function sendemail() { MailApp.sendEmail("[email protected]", "F-106", "Aircraft Dispatch");

I want to send the sheet I'm using at the time to a predetermined address.

1
current sheet or current spreadsheet?J. G.

1 Answers

1
votes

Try this:

function emailCurrentSheetAsPDF() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var shts=ss.getSheets();
  for(var i=0;i<shts.length;i++) {
    if(shts[i]!=sh) {
      shts[i].hideSheet();
    }
  }
  var fldr=DriveApp.getRootFolder();
  var file=fldr.createFile(ss.getBlob().getAs('application/pdf'));
  GmailApp.sendEmail("[email protected]", "F-106", "Aircraft Dispatch",{attachments:[file]});
  file.setTrashed('true');
}