views:

240

answers:

1

I have an application which uses the MS-Word API. I get stuck when trying to use the function Document.Open(Filename) which is the function that is opening a document. It doesn't matter if I run in debug or release mode. Any help would be appreciated. Thank you, Guy Marom

A: 

There are a bunch more paramters you need for the Open method!

object fileName = "MyDocuemnt.docx";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
aDoc.Activate();

The Word (and Office) API from .Net requires all paramters as opposed to VBA, hence the long line of missing's

It's a pain, but you can make some wrapper classes to hide this from your main application logic if the solution is to become large and complex

1) The code runs fine if I run it as a windows service on my machine.2) I don't want my document to be visible so I set: WordApp.Visible = False isVisibile = False
Guy Marom
You shoudln't run Word as part of a windows service (see MSDN). What are you trying to do? The visible bit is of course optional :-)
I have several applications using word automation:1) The service - Sends DOC/DOCX files to the printer.2) A word add-in that uses automation to explore a mail merge datasource.I just noticed that these problems are related to the fact that I use word in a different thread than the main thread.
Guy Marom