So far i have gotten the Code below to work the way i would like it to but i just want to send the PFD as a Landscape, I understand that the Landscape thing have been posted before but i can not get them to work can anyone help?
Thanks,
function onOpen() {
var submenu = [{name:"Email Sheet", functionName:"exportActiveSheets"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu('Email Script', submenu);
}
function exportActiveSheets() {
// Set the Active Spreadsheet
var originalSpreadsheet = SpreadsheetApp.getActive();
// Set the message to attach to the email.
var message = "Please see attached";
// Get Project Name from Cell A1
var projectname = originalSpreadsheet.getRange("D2:Q2").getValues();
// Get Reporting Period from Cell B3
var period = originalSpreadsheet.getRange("D2:D2").getValues();
// Construct the Subject Line
//var subject = projectname";
var subject = "Press Production Run's for Tonight";
// Get email details from "List" sheet and construct To: Header
var contacts = originalSpreadsheet.getSheetByName("List");
var numRows = contacts.getLastRow();
var emailTo = contacts.getRange(3, 2, numRows, 1).getValues();
// Create a new Spreadsheet and copy the current sheet into it.
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var projectname = SpreadsheetApp.getActiveSpreadsheet();
sheet = originalSpreadsheet.getActiveSheet();
sheet.copyTo(newSpreadsheet);
// Find and delete the default "Sheet 1", after the copy
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
// Make PDF
var pdf = DriveApp.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();'
var attach = {fileName:'Tonights Jobs.pdf',content:pdf, mimeType:'application/pdf'};
// Send the freshly constructed email
MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
// Delete temp sheet
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
}