File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Detecting if Word is running using Jacob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Detecting if Word is running using Jacob" Watch "Detecting if Word is running using Jacob" New topic

Detecting if Word is running using Jacob

Jonathan Moore
Ranch Hand

Joined: Nov 02, 2005
Posts: 36

Another Jacob question. I've found that if you already have Word open when generating a document using Jacob you get problems when trying to close Word. Specifically calling

ActiveXComponent wordApp = new ActiveXComponent("Word.Application");

will open a new instance of Word. When you attempt to close this you get the error message

"This file is in use by another application or user.
(C:\Documents and Settings\...\"

When you click "OK" it opens a "Save As" dialog for you to ave the template.

It seems that the first Word instance has a lock on the template, and the 2nd is trying to update it (not sure why) but this will cause confusion and problems for my users (especially as Word will be run with visibility off).

So my question is, is there a way to prevent this? Currently I have checked the task list to see if Word is running and give the user a message to close it but that seems a bit heavy handed. Is there a way of connecting to the existing Word instance rather than creating a new one? Alternatively is there a way of resetting the template location (to say a temp directory) to prevent the lock clash.

Thanks for any help.

Don't get me started about those stupid light bulbs.
subject: Detecting if Word is running using Jacob