JavaScript for Automation (JXA) Excel open workbook question

260 Views Asked by At

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".

1

There are 1 best solutions below

1
hustlefan On BEST ANSWER

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