I am trying to save an Excel 2016 spreadsheet as a PDF file. I have following simple Applescript that is called from within an Objective C program:
on saveExcel
Here's a script for Excel 2016 (version 15.22).
I've added comments in the script:
on saveExcelAsPDF(documentPath, PDFPath) -- params = two HFS paths
set tFile to (POSIX path of documentPath) as POSIX file -- get a posix file object to avoid grant access issue with 'Microsoft Office 2016', not the same as (file documentPath) when using the 'open ...' command
tell application "Microsoft Excel"
set isRun to running
set wkbk1 to open workbook workbook file name tFile
alias PDFPath -- This is necessary to any script for 'Microsoft Office 2016', this avoid errors with any "save ... " command
save workbook as wkbk1 filename PDFPath file format PDF file format with overwrite
close wkbk1 saving no
if not isRun then quit
end tell
end saveExcelAsPDF