Multiple Word Applications

B

Brent Marcotte

We are using Word in unattended server applications and we
need to either have several instances of the same app or
multiple apps that are all accessing Word. Each instance
attempts to create it's own Word application object and
this works successfully most of the time. However, once
in a while the apps get confused and seem to be getting an
instance of Word that is already in use by another app.

I have two questions:

1) Does anyone know of a way to ensure that you are always
getting a new instance of Word?

2) Does anyone know of a way to identify a specific
instance of Word in order to close/kill the instance if
errors are encountered or an external timeout has been
exceeded and we want to end the process.

Thanx
 
J

Jezebel

I have two questions:

1) Does anyone know of a way to ensure that you are always
getting a new instance of Word?

From VB/VBA or similar:

set WordApp = new Word.Application or
set WordApp = CreateObject("Word.Application")

From the command line

winword.exe / (Check the MS site for the full list of command-line
switches; there's also /n -- "Starts a new instance of Word with no document
open. Documents opened in each instance of Word will not appear as choices
in the Window menu of other instances."
2) Does anyone know of a way to identify a specific
instance of Word in order to close/kill the instance if
errors are encountered or an external timeout has been
exceeded and we want to end the process.

Best is to maintain a reference to the object when you create it. Otherwise
how will you know which instance you want?
 
B

Brent Marcotte

1) I am using 'set WordApp = new Word.Application' but we
still experience some peculiarities

2) Sorry, I should have been more specific...I have a
component that uses various other 3rd party applications
to convert to PDF...including Word. Sometimes the other
third-party applications fail or pop-up a message box
which in effect leaves them and the component hung. Rather
than leave the process hung, after a timeout period I
destroy the component and then attempt to recreate the
component so that my app can continue processing. So what
I would like to do is set some kind of identifier upon
instantiation and then later be able to either reconnect
to or to search for and destroy a specific instance of
Word based on that identifier. I am just not sure
how/where I can set/search for the identifier.

I should also mention, that I am using Word 2000.....if
someone knows whether or not these problems are addressed
in Word 2003...please let me know.
 
J

Jay Freedman

Hi Brent,

The article at http://support.microsoft.com/default.aspx?kbid=257757
discusses some of the gotchas that lead MS to make the following
statement:

"Microsoft does not currently recommend, and does not support,
Automation of Microsoft Office applications from any unattended,
non-interactive client application or component (including ASP, DCOM,
and NT Services), because Office may exhibit unstable behavior and/or
deadlock when run in this environment."

In other words, "yer on yer own..." :-(

To answer your first question, the only thing I can think of is to
look at the caption of the Word window you've just acquired, and if it
doesn't contain "Document 1" then discard the object and try again.

Assuming you can solve that problem, then each app should have an
object handle to a specific Word Application instance containing a
specific Document object. When you detect a problem in a given object,
kill off that object.
 

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