I am trying to use applescript to save an excel worksheet as a pdf. I looked on microsoft’s Excel2004AppleScriptRef.pdf file. This guide is obviously for Excel 2004. I could not find one for 2008. In the guide, I saw the “save as” command had all the possible file types listed. Unfortunately, pdf was not listed.
I will take any kind of work-around (be it with applescript or with automator) to save this file as a pdf. I have tried using automator, BUT I need the filename to change with each time the script is run.
So, my goal is:
save the active worksheet in an excel file as a pdf in a folder on the desktop.
each time, have the filename change. (but still put in the same folder)
Can anyone help? I am new to applescript, but not new to coding in general. (I would have been able to do this in VBA in about 10 minutes…alas, I cannot use it.)
Did you find out how to do this? I’ve been trying to do the same thing.
All I got up 'till now is to save the workbook as PDF, then you get 1 PDF for every sheet.
As a workaround I guess you could just delete all the sheets you don’t want, then save the workbook.
You can do that like this:
tell application "Microsoft Excel"
activate
open ((path to desktop as text) & "thefile.xls")
set display alerts to false -- if you don't want Excel to ask for confirmation of deleting
delete sheet 1 -- sheet number or sheet name
end tell
The biggest workaround would be to save the workbook as PDF, then delete all the PDF’s you don’t want.
But I really hope there’s a better way.
I could be totally off the mark here, but if you set your default printer to be "Acrobat PDF 8.0’, it should print to pdf automatically. I think you could get the current sheet’s name and save it as that. System Events to keystroke in that text then System Events to hit the RETURN to save.