How to turn old incompatible .xls files into .xlsx?

I’ve just been trying to open them in excel and then save as .xlsx but I keep getting “parameter error”.

set destpath to “/Users/augustinmarcial/Desktop/Gas Exchange/Fbox Decoys Round2/Sheets”
set hfsPath to destpath as POSIX file as string
tell application “Microsoft Excel”
activate
open file
save workbook as active workbook filename hfsPath
end tell

‘open file’ requires a parameter.
You weren’t telling Excel the name of the file to open.
Here is my code using a file on my Mac called “Casino Night.xls”

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set hfsPath to (path to desktop folder as text) & "Casino Night.xlsx" --"Gas Exchange:Fbox Decoys Round2:Sheets"
tell application "Microsoft Excel"
	activate
	open file "Ventura SSD:Users:robert:Documents:Casino Night:Casino night pd tickets.xls"
	save workbook as active workbook filename hfsPath
end tell

Also please learn how to post code properly.
You put 3 ticks ( ) on one line, followed by your code, then on a last line 3 more ticks. ( - on US keyboards its on the key left of the 1 key, on a key with the tilde ~ )

Hello, thank you for your help. Is there a way to adapt this so that I can use the quick action on a group of files at a time?

I’m assuming you have the files selected already in the finder? or would you like the script to ask the user to choose the files in a choose file dialog?
And what about the destination, should it be in the same folder as each file, or again ask the user where to put them?

I guess I was thinking I go to finder, highlight a bunch of files, hit my quick action and then they are all converted to xlsx in place as I have no use for the less compatible .xls files

I personally use the Script Menu in the menu bar. Each Application shows its own scripts there for easy access.
You turn on the Script Menu in the preferences of the “Script Editor” application.
The folder location for the scripts is in the users “Library” folder, in a sub-folder called “Scripts”. Inside there is another sub-folder called “Applications”, inside which you create a folder for each application you want scripts added for. In the case of Excel, you create a subfolder here called “Excel”. Add any script you want available to Excel here.

Hello, I still have two persisting issues. This is my code:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set hfsPath to "Gas Exchange:Fbox Decoys Round2:Sheets" & "ahm2-col0-1e-2025-3-31_.xls"
tell application "Microsoft Excel"
	activate
	open file "Macintosh HD:Users:augustinmarcial:Desktop:Gas Exchange:Fbox Decoys Round2:Sheets:ahm2-col0-1e-2025-3-31_.xls"
	save workbook as active workbook filename hfsPath
end tell
  1. I am still getting a parameter error from excel, its doing just fine opening the file but maybe having a hard time saving it.

  2. I want to avoid having to type in the path for each individual file each time, is there a better way to do that for many files at a time?

I just want a simple script to take a file I select and re-save it as .xlsx instead of the outdated .xls
Thank you

Here is my latest…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

local hfsFiles, hfsPath, hfsFile, tid
try
	set hfsFiles to choose file with prompt "Choose one or more Excel files to convert to \".xlsx\"" of type {"xls"} default location alias (path to desktop folder as text) with multiple selections allowed
on error
	return
end try
set tid to text item delimiters
set text item delimiters to ":"
repeat with hfsFile in hfsFiles
	set hfsFile to contents of hfsFile as text
	set hfsPath to text items of hfsFile
	set text item delimiters to "."
	set fname to text items of item -1 of hfsPath
	set text item -1 of fname to "xlsx"
	set item -1 of hfsPath to fname as text
	set text item delimiters to ":"
	set hfsPath to hfsPath as text
	tell application "Microsoft Excel"
		activate
		open file hfsFile
		save workbook as active workbook filename hfsPath
	end tell
end repeat
set text item delimiters to tid

** EDIT ** - I fixed it

Hello, thank you so much for your help and the time you spent. I found a much easier way by using libreoffice and command line, but I really appreciate it.

Did you try my script?

Yes, it still gave me the parameter error after opening the file, I’m unsure why its doing that.

I fixed it (found a bug)

** EDIT **

Here is a newer version that closes the window of each file and also deletes the old XLS file…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

local hfsFiles, inFile, outFile, tid, aWin, myWins
try
	set hfsFiles to choose file with prompt "Choose one or more Excel files to convert to \".xlsx\"" of type {"xls"} default location alias (path to desktop folder as text) with multiple selections allowed
on error
	return
end try
set tid to text item delimiters
set text item delimiters to ":"
repeat with inFile in hfsFiles
	set inFile to contents of inFile as text
	set outFile to text items of inFile
	set text item delimiters to "."
	set fname to text items of item -1 of outFile
	set item -1 of fname to "xlsx"
	set fname to fname as text
	set item -1 of outFile to fname
	set text item delimiters to ":"
	tell application "Microsoft Excel"
		activate
		open file inFile
		save workbook as active workbook filename (outFile as text)
		set myWins to windows
		repeat with aWin in myWins
			if caption of aWin = fname then
				close aWin
				exit repeat
			end if
		end repeat
		-- do stuff here to delete old xls file
		tell application "System Events" to move file inFile to trash
	end tell
end repeat
set text item delimiters to tid

image

You need a colon “:” here.

Updated 2025-04-25T00:58:00Z

You’re getting the error precisely for the reason stated in the message of the error: a wrong parameter supplied to a command.

According to the Excel AppleScript reference, you’re better off using open workbook rather than open. However, speaking of the latter, you supplied it incorrectly because it doesn’t know what it opens: open file is an invalid reference. It’s this place that might be causing trouble.



To be able to open as .xlsx, you must save it in a legit format.

save workbook as _workbook_ file name _name file format SYLK file format



Made a minor edit to my last script posted.

Here is my take on the problem. It takes the selected files in the Finder and filters them to restrict processing to ‘xls’ files. Then, after closing any open workbooks, opens each in Excel, saves as an ‘xlsx’ file (workbook normal file format) and then closes the workbook. Note that the way that save workbook as works, it bases the output file format on the extension. So in this case, I just added an ‘x’ to the string.

-- get list of selected 'xls' files
tell application "Finder"
	set salt to selection as alias list -- all selected files
	set selectionList to {}
	repeat with sel in salt
		if name extension of sel is "xls" then
			-- set end of selectionList to (contents of sel as text)
			set end of selectionList to (contents of sel as text) -- list of file paths 
		end if
	end repeat
end tell

-- open each selected 'xls', save as 'xlsx', then close
tell application "Microsoft Excel"
	close workbooks -- close any existing windows
	repeat with pathFile in selectionList
		set convertee to open workbook workbook file name pathFile -- open workbook
		save workbook as convertee filename (pathFile & "x") -- add 'x' to extension to make 'xlsx' format
		close workbook (get name of front workbook) -- close workbook
	end repeat
end tell
-- selectionList

I find that working with selected files is the easiest approach for this kind of task but it would be straightforward to change the set salt… line to use choose file or work on the contents of a folder.

As to using the script… I would put it in the script menu: if it isn’t already enabled, enable ‘Show script menu in menu bar’ in Script Editor’s Preferences > General, and then save the script in the ‘~/Library/Scripts/Applications/Finder’ folder. You’ll end up with a script icon up near where the date/clock is and when the Finder is active, you can click first on the script menu and then the saved script to run it.

Alternatively, you could create an Automator ‘service’ or whatever Quick Actions provides, and then put the script inside a ‘run applescript’ action within that. It would require a bit of tweaking (a line or two) to allow Automator/Quick Actions to provide the list of files to process but it isn’t complicated.

Finally, I don’t think you can replace them in place as excel doesn’t seem to do that. But robertfern has a line that deletes the originals in his script. You could also manually just trash the selected files (or have the script do that). There are a couple of approaches to do that.

Aside
SYLK file format

If ‘xls’ is an outdated format, what does that make ‘SYLK’. It goes back to all-caps days and predates Excel. For everyone’s sake, please avoid this format.