Home » excel » Applescript will not open Excel 2011 workbook

Applescript will not open Excel 2011 workbook

Posted by: admin May 14, 2020 Leave a comment

Questions:

Can somebody please tell me what is wrong with the following applescript

set sourceFile to (choose file with prompt "Choose source files" of type {"XLS6", "XLS7", "XLS8", "XLS", "TXT"} with multiple selections allowed without invisibles)
tell application "Microsoft Excel"
-- activate
open workbook workbook file name sourceFile
end tell

I am getting the following error

error "Microsoft Excel got an error: Can’t continue open workbook." number -1708

The script works if I hard code an individual file path, so problem must be in the set sourceFile line, but I need to be able to choose a file as it will not always be the same.

How to&Answers:

Try this:

set sourceFile to (choose file with prompt "Choose source files" of type {"XLS6", "XLS7", "XLS8", "XLS", "TXT"} with multiple selections allowed without invisibles) as string
tell application "Microsoft Excel"
open sourceFile
end tell