Programmatically open excel

I have several AutoIt scripts that parse Excel files. However, with LibreOffice installed and Microsift Office uninstalled, I get errors creating an Excel object via ObjCreate(“Excel.Application”). Is there a way to do this with Lffice?

Unexpectedly LibreOffice isn’t Excel Application :slight_smile:

Actually, there were several attempts to add MSOffice Automation wrappers around OpenOffice/LibreOffice. One of them is named AutomateIt :slight_smile: - but that’s a different project with similar name. It is incomplete, and the level of its suitability might not fit your needs - but you could try to check that. Another similar project is UniOffice@Etersoft (Russian only).

My example uses CreateObject, so doesn’t that mean automation? However, I am far from an expert in COM.

It does use Automation, but not MSOffice automation. That’s what I mean. The programs that assume MSOffice COM objects cannot use LO automation objects.

However, since asker’s case is about self-made solution, it’s most possible that your answer is the correct one. :slight_smile:

OK, that makes sense.

The VBScript example you gave opens a NEW spreadsheet; I need to open an existing spreadsheet (an .xlsx or .xls file).

Here is a VBScript automation example that opens an existing file in LibreOffice Calc. Replace CreateObject with ObjCreate.

Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
Set oDoc = oDesk.loadComponentFromURL("file:///path/to/test.xlsx", "_blank", 0, Array())

Or this to create a new blank spreadsheet, which could be saved as .xlsx if needed.

Set oDoc = oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, Array())

Documentation for loadComponentFromURL is under XComponentLoader.

How about using VBScript to open an existing file? If I can do this with VBScript, I can probably figure out how to do it with AutoIT.

That’s precisely what the example shows. It sounds like you did not read the edited answer carefully or try to run the code. I edited the wording in the answer to make it clearer.

Your sample code worked for me. Now I will try to make an AutoIT script to do the same thing. Also, I have to Open the file without actually displaying the GUI so I can pragmatically read the contents.

I found an old but excellent set of AutiIT library functions that support LO file manipulation. I think I’m on my way. Thank you. Here is a link to the AutoITcode: