Word Interop

C

Chuck Norris

Hi everybody,
A question about how to use 'Microsoft.Office.Interop.Word'.
I'm trying the following code:

Application app = new Word.ApplicationClass();
Document doc = app.Documents.Open(ref templateFile,...);
//...
//replace bookmarks...
//...
doc.SaveAs(ref newFile,...);
doc.Close(...);
doc.Quit(...);

It works very well but when the templateFile is already opened in
another Word instance,
the following dialog box appears in my .NET app.:
If few word the box says:

"File already in use", the templateFile is blocked.
Then 3 radiobuttons to make a choice:
- open a read-only copy
- create a local copy
- wait until the file is ready

Now I don't want this dialog box to appear, I want my app to work even
if the templateFile is already opened,
because the template remains unchanged in any case and the app always
saves a copy of it.

Someone can help me!

Thanks,
Bye.
 
N

Norman Yuan

The "templateFile" is a *.doc file, right?

To avoid that (being opened in another Word, on the same computer or on
other computer), you could make the the template file a "*dot" file (Word
Template file. and change the code like this:

Document doc = app.Documents.Open(ref templateFile,...);
....

doc.SaveAs(...);

To

Document doc = app.Documents.Add([the template file]);
....
doc.SaveAs(ref newFilename);
 

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