Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Detecting if Word is running using Jacob

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!