I'm trying to batch process converting a folder of .xls files to .csv using Applescript for MS Excel V15.15. I'm using a sample I found online to model it :
set theOutputPath to (path to desktop folder as string) & "My Saved Workbook.csv"
tell application "Microsoft Excel"
tell active workbook
save workbook as filename theOutputPath file format CSV file format
end tell
end tell
This is the script that fails consistently, though it seems to most closely resembles the model:
set csv_folder to "Macintosh HD:Users:Me:CSV:" & file_name as string
tell application "Microsoft Excel"
open Source_file
tell active workbook
save workbook as filename csv_folder file format CSV Mac file format-->
(*This generates error "Microsoft Excel got an error: Parameter error." number -50 *)
end tell
end tell
I have also tried:
set csv_folder to "Macintosh HD:Users:Me:CSV:" & file_name & ".csv" as string
tell application "Microsoft Excel"
open Source_file
tell active workbook
save workbook as filename csv_folder -->
(*This usually generates error "Microsoft Excel got an error:
Parameter error." number -50 the first time it is run,
then works the 2nd time *)
end tell
end tell
EDIT:This latter script, though it completes does not result in a true csv file, as when I open it with BBEdit it is showing code, not the file contents.
I have also tried setting the cv_folder without using "as String". Any ideas why this fails? It does not seem to like the syntax "save workbook as filename theOutputPath file format CSV file format".
Best Answer
For Excel V15, use a posix path, like this:
Edit 1 -
I test it on V15.15 and V15.16, it's a bug when the destination folder doesn't contains a recently opened Excel file. So use it
Edit 2 -
Or create an empty file like this
Edit 3 : I had another idea, it would be the simplest script.