Problem with C# Word Automation when a user opensanother word document

A

Adam

Hi all,

I hope I'm posting in the correct place. I have been searching for a few hours now and I haven't been able to find a solution as yet.

I have successfully been able to write a C# program which automates word to produce a series of word documents (1,000+ pages each).

The problem I am finding is that when a user opens Word it's creating a new document within the instance of Word which was created by my C# program. When this occurs it causes my program to crash because its attempts of start entering data within the new document instead of the original document created by my program.

Is there any way to force word to create a new instance of word for any documents opened or created (by the user themselves) while my program is working with it's instance of word.

I've noticed that if another copy of word is running before my program creates it's instance there is no problems.

I'd appreciate anyones help.

Thanks, Adam

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
C

Cindy M.

I have successfully been able to write a C# program which automates word to
produce a series of word documents (1,000+ pages each).
The problem I am finding is that when a user opens Word it's creating a new
document within the instance of Word which was created by my C# program. When this
occurs it causes my program to crash because its attempts of start entering data
within the new document instead of the original document created by my program.
Is there any way to force word to create a new instance of word for any documents
opened or created (by the user themselves) while my program is working with it's
instance of word.
I've noticed that if another copy of word is running before my program creates
it's instance there is no problems.There's not really any way to reliably control this, no.

However, if you assign the document you need to work with to a (class-level,
perhaps) variable when you create it, you should be able to work with that document
without conflicting with the user. AVOID using any construct such as ActiveDocument
or Selection.

Word.Document Doc = wdApp.Documents.Open(ref oTemplate, //other params);

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top