Open File Excel Problem

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?

Hello.

It seems to me, that you have tried to open a list consisting of an alias to a folder, and an alias to a file in your script. I have coerced the first path to text and concatenated the second one in the little snippet below, so that it is a valid path for the open command. I haven’t used Excel for this, so you may have to coerce theFilename, to an alias (theFilename as alias), when you try to insert it into your script.

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 as text) & item x of the_folder_list
	open thefile
end repeat

it works perfect with your change. Thank you