I’m writing an application that needs to Automate MS Word. I’m using the MSOfficeAutomation.rbx plugin with the following bit of code:
Dim word as WordApplication = New WordApplication
I have Office 2013 installed.
If I run my program and Word is NOT running, I get an OLEAutomation error:
Exception Message: Unknown Error: -2146959355
Exception Error Number: -2146959355
If Word is running, the application runs as expected.
Is this a bug? Is the expectation that the Office application needs to be actually running to be able to automate it?
I copied the MSOfficeAutomation.rbx plugin from \Extras\Office Automation\ and pasted it into the \plugins\ folder. Make sure that Xojo is restarted so that the plugin is loaded.
I typed the following code in Xojo 2016r4 with Office 2013 and it worked.
Dim word as WordApplication = new WordApplication
Word.Documents.add
Word.visible = true
There was not an instance of Word running when I used this code. I tried this on Office 2016 and 2010 and it worked on my systems. Is it possible that Office may need to be reinstalled? This is just a guess.
Ok, this problem is because I have more than one version of Office installed on my PC and that has caused problems with the OLE automation. All runs fine on the client’s site (and any other PC with just one version of Office)