Applescript in Excel 2008


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:

  1. save the active worksheet in an excel file as a pdf in a folder on the desktop.
  2. 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.)


surely, you will get what you want. Someone in this forum will help you within a few minutes.
just want you to know, you can use

and you can change output location in “cups-pdf.conf” file

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"
	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.

Any help on this subject?


I can’t figure out how to specify the file name.
The Print To File agrument of PrintOut is not supported.

You could use this

tell application "Microsoft Excel"
	show (get dialog (dialog print))
end tell

and use the PDF button in the dialog screen

Thanks for the tip.
I think I’m gonna stick with the delete-sheet thing if there isn’t a way to save sheets in the “save as” command.


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.

  • Zoar