Reuben Smith

I'm having a lot of difficulty trying to do simple things with Word 12.0 Object Library.

1) When I try to create a new document...

Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document oDoc =
oWordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

Documents.Add returns null, and Documents.Count is still 0.

2) When I try to open an existing document....

oDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

it hangs at this statement and I have to stop it (I waited like 15 minutes).

Can anyone help Please!! And thank you.


Re: Visual Studio Tools for Office A lot of pain with Word automation

Reuben Smith

It turns out the problem was that I was invoking the code through a web service. If I run the same code from a local project it seems to work fine. However I need to generate word documents from a webserver (simple documents, nothing fancy). Any advice




Re: Visual Studio Tools for Office A lot of pain with Word automation

Andrew Cherry [MSFT]

Hi Reuben -

This may appear as a second answer, as the forum software didn't like my last answer.

There are numerous KB articles and other inquiries to elaborate, but the basic answer is "Don't run Word on a server."

However, for piecing together basic (or even complex) files, the new Office Open XML file formats are light years ahead of automating Word directly. Even if you need to support downlevel (Office 2003), a file importer is available for free for Word 2003. I would strongly recommend looking into using the file formats directly on the server.

That being said, <begin completely unsupported and ill-recommended guidance here>you may have some luck if you ensure that there is a console available for Word to run on, rather than just a console-less service. Word expects UI to be present. </bad ideas>

Again, I highly recommend working directly with Word files, rather than with the Word application -- between OOXML and Word's new Content Controls, you'd be surprised what you can accomplish.

HTH,

Andrew