(* Drag and drop conversion (duplication) of Microsoft Excel files to PDF files using Excel 2008. *)
on open fillist
set bs to "/"
set d to "-"
tell application "Finder"
set defLoc to container of (item 1 of fillist) as alias
end tell
set destn to choose folder with prompt "You are converting (duplicating) Excel files to PDF files" & return & "Select a location to save converted files." default location defLoc
repeat with lvar in fillist
tell application "Finder"
set thename to name of lvar
set filex to name extension of lvar
set l to length of filex
end tell
set nuname to text 1 thru text item -(l + 1) of thename
if "/" is in nuname then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to bs
set txtLst to every text item of nuname as list
set AppleScript's text item delimiters to d
set nuname to txtLst as string
set AppleScript's text item delimiters to oldDelims
end if
set filname to (destn as string) & nuname & "pdf"
tell application "Microsoft Excel"
launch
open lvar
save as active sheet filename filname file format PDF file format
close window 1 saving no
end tell
end repeat
end open
HTH
J
On Dec 16, 2014, at 1:52 PM, Bill Guion <
email@hidden> wrote:
I'm trying to create and save an Excel worksheet as a .pdf file. The script below is my current attempt. I have removed all of the Excel manipulation portion of the script to help focus on the file save portion. The manipulation portion works just fine. The script starts by prompting me for a csv file. The display dialogs all show the values I expect for the various values. The script runs without error, but no file is saved. I would really appreciate someone pointing out my errors.
-- find the csv file
set myLifeList to choose file with prompt "Locate Bill's Life List"
-- define folder to save .pdf into
set pdfSavePath to "/Macintosh HD:Documents:pdfs:" as string
tell application "Microsoft Excel"
activate
open myLifeList
end tell
SNIP
tell application "Microsoft Excel"
copy value of cell "N2" to filename
display dialog "filename is " & filename
display dialog "pdfSavePath is " & pdfSavePath
set fullName to pdfSavePath & filename & ".pdf"
display dialog fullName
try
save active sheet in fullName as PDF file format
end try
end tell
Thanks in advance.
-----===== Bill =====-----