0

How do you open an Excel workbook using JavaScript for Automation?

let excelApp = Application("Microsoft Excel");  
let path = Path("/Users/me/Test.xlsx");
excelApp.openWorkbook(path);  

gets error 50 "parameter error".

hustlefan
  • 1
  • 3

1 Answers1

0

I figured it out:

let excelApp = Application("Microsoft Excel");
let testWorkbook = excelApp.openWorkbook({workbookFileName: "/Users/me/Test.xlsx"});

I also figured out how to get the contents of the data:

let varr = testWorkbook.sheets["firstsheet"].usedRange.value();

source: Yosemite JXA release notes and Script Editor dictionary entry for Microsoft Excel

hustlefan
  • 1
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 22 '22 at 02:40