Word Automation

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?

Hi Jim,

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

Does this work on your computer?

@Eugene Dakin - I’ve copied the MSOfficeAutomation.rbx from the Extras folder and put it in the plugin folder. I’ve restarted Xojo to load the plugin.

I’m running Xojo 2016r4 with Office 2013.

For me, the code only works if Word is already running. So the question is, did you have an instance of Word running when you ran your code?


Maybe you need this:

Check the second constructor. Pass “True” or “False” and check for errors. It has an example of it.

Hi Jim,

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.

I own a e-book about programming MS Word with Xojo. A good way to take off quickly. The writer is @Eugene Dakin.

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)