Since this post is quite recent & directly applies I wanted to insert myself into the conversation. I am trying to create a script I can use to save an entire Excel Document (not a single sheet) as a PDF.
I am finding that the final save step is not working. I get an ambiguous error from “Microsoft Excel got an error: Parameter Error” and the error window had a -50 in the lower left corner which I believe is the error code (the screen shot of the error screen from Script Debugger is attached).
The script I am using is included below and the save step is the same as the example in the previous posts. I have tried several different variants of the save step using different dictionary versions of save (Standard Suite & MS Office Suite) and all result in the same error. I am wondering if the issue is either sandbox related or perhaps a setting in Excel that I have not uncovered.
I have “borrowed” the SplitString function from the previous posts so thanks!
----------------------- Script Below ---------------
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on open theFileList
local currentPOSIXfile, CurrentFileAlias, txtList, currentPOSIXPDFFileRef, PDFPOSIXfileName, savedPDFfile
local wkbook1, isRun
repeat with CurrentFileAlias in theFileList
set currentPOSIXfile to (the POSIX path of CurrentFileAlias)
set PDFPOSIXfileName to my replaceExtension(currentPOSIXfile, "pdf") as string
-- set currentPOSIXPDFFileRef to POSIX file PDFPOSIXfileName
tell application "Microsoft Excel"
set isRun to running
set wkbook1 to open workbook workbook file name currentPOSIXfile
save as document 1 filename PDFPOSIXfileName file format PDF file format
close wkbook1 saving no
-- Handle the case where the script is launched without any dropped files
open (choose file with multiple selections allowed)
-- The following was taken from the ScriptDebugger forums.
on SplitString(TheBigString, fieldSeparator)
set oldTID to text item delimiters
set text item delimiters to fieldSeparator
set theItems to text items of TheBigString
set text item delimiters to oldTID
on replaceExtension(filename, newExt)
local txtList, newFileName, numItems
set txtList to my SplitString(filename, ".")
set numItems to number of items in txtList
if numItems is 1 then
-- If there is only 1 item in list there is no extension
-- so we will simply add the .pdf extension
set newFileName to txtList & "." & newExt
-- Other wise the last item in the list is the extension so
-- we will replace it with the .pdf extension and then
-- rebuild the filename from these pieces
set last item of txtList to newExt
set newFileName to ""
set itemNum to 0
repeat numItems times
set itemNum to itemNum + 1
if itemNum is 1 then
set newFileName to item itemNum in txtList
set newFileName to newFileName & "." & item itemNum in txtList
----------------Screen shot of error screen-------------------------