I am trying to open multiple files in a folder -
Each time I run the script it generate this error:
error “Microsoft Excel got an error: {alias "Macintosh HD:Users:dlaurentny:Desktop:DB:F1278497:", "F1278497.DailyExport.20131125.csv"} doesn’t understand the “open” message.” number -1708 from {alias “Macintosh HD:Users:dlaurentny:Desktop:DB:F1278497:”, “F1278497.DailyExport.20131125.csv”}
set the_folder to (choose folder with prompt "Choose Folder to Operate On")
set the_folder_list to list folder the_folder without invisibles
--set theFile to (choose file with prompt "Select the Excel Spreadsheet to Convert:")
set outputDirectory to (choose folder with prompt "Select Folder to Output To:")
repeat with x from 1 to count of the_folder_list
set thefile to the_folder & item x of the_folder_list
tell application "Microsoft Excel"
-- Get Excel to activate
activate
-- Close any workbooks that we have open
close workbooks
-- Ask Excel to open the theFile spreadsheet
open thefile
-- Set maxCount to the total number of sheets in this workbook
set maxCount to count of worksheets of active workbook
-- For each sheet in the workbook, loop through then one by one
repeat with i from 1 to maxCount
if i > 1 then
open thefile
end if
-- Set the current worksheet to our loop position
set theWorksheetname to name of worksheet i of active workbook
set theWorksheet to worksheet i of active workbook
activate object theWorksheet
-- Save the worksheet as a CSV file
set theSheetsPath to outputDirectory & theWorksheetname & ".csv" as string
save as theWorksheet filename theSheetsPath file format CSV file format with overwrite
-- Close the worksheet that we've just created
close active workbook saving no
end repeat
-- Clean up and close files
close workbooks
end tell
end repeat
If I remove the Folder_List Loop and simply select a single file, rather than a folder - It works as expected:
set theFile to (choose file with prompt "Select the Excel Spreadsheet to Convert:")
set outputDirectory to (choose folder with prompt "Select Folder to Output To:")
--repeat with x from 1 to count of the_folder_list
--set thefile to the_folder & item x of the_folder_list
tell application "Microsoft Excel"
-- Get Excel to activate
activate
-- Close any workbooks that we have open
close workbooks
-- Ask Excel to open the theFile spreadsheet
open theFile
-- Set maxCount to the total number of sheets in this workbook
set maxCount to count of worksheets of active workbook
-- For each sheet in the workbook, loop through then one by one
repeat with i from 1 to maxCount
if i > 1 then
open theFile
end if
-- Set the current worksheet to our loop position
set theWorksheetname to name of worksheet i of active workbook
set theWorksheet to worksheet i of active workbook
activate object theWorksheet
-- Save the worksheet as a CSV file
set theSheetsPath to outputDirectory & theWorksheetname & ".csv" as string
save as theWorksheet filename theSheetsPath file format CSV file format with overwrite
-- Close the worksheet that we've just created
close active workbook saving no
end repeat
-- Clean up and close files
close workbooks
end tell
Can anyone tell me what is wrong with the first script?