Automate Word - File in Use error.

  • Thread starter Thread starter Steve Barnett
  • Start date Start date
S

Steve Barnett

Hi,
I'm attempting to automate word to load a document. I have no problem if
Word isn't loaded yet as creating a new Word.ApplicationClass() loads it for
me. However, there will be times when Word is already loaded and I want to
connect to that copy (and check whether the document is already loaded).

When Word is already loaded, creating a new Word.ApplicationClass() loads
another copy of Word and tries to load my document again. I then get an
error message telling me the file is in use.

I'm having some problems working out how to get the ApplicationClass if an
already running copy of Word... anyone know how I do that?

Thanks
Steve
 
Steve Barnett said:
Hi,
I'm attempting to automate word to load a document. I have no problem
if Word isn't loaded yet as creating a new Word.ApplicationClass() loads
it for me. However, there will be times when Word is already loaded and I
want to connect to that copy (and check whether the document is already
loaded).

When Word is already loaded, creating a new Word.ApplicationClass() loads
another copy of Word and tries to load my document again. I then get an
error message telling me the file is in use.

I'm having some problems working out how to get the ApplicationClass if an
already running copy of Word... anyone know how I do that?

Thanks
Steve

You should connect to the running instance using Marshal.GetActiveObject.

Willy.
 
That's terrific, thank you. I would never have gotten there!

I'm struggling so badly getting my head around the classes available to me
in C#... things were so much easier with VB6, where you have to do
everything yourself!

Steve
 
Back
Top