Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Word macro from java getting read only popup

 
Vishal Alhat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am calling word macro from java program with the help of JACOB(14) lib. It actually calling macro in loop, in every iteration it calls macro once. Where it actually bookmarks paragraphs in given document .
For every call of macro it opens given word document bookmark paragraph and closes it , I know this may not be ideal way , but now its a scenario
When we try to run two or more instances of java program which calls macro, simultaneously it gives error for word document that the "document is locked by user do you want to open it in read Only mode "

I am not able to identify it is problem with java or word macro or JACOB lib.


Also i wanna know when we call native method JVM waits for native method to complete or not???

Thanks in advance!!!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a problem at all: two users can't modify an open Word document at the same time.
 
Vishal Alhat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh sorry forgot to mentioned, for two different document it is giving error.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are Java code, JACOB and Word macro all thread-safe? I'm not familiar with this setup, but it sounds like the type of issue that might happen if code is not thread-safe.
 
Vishal Alhat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (int i = 0; i < docParts.size(); i++) {
d = (DocPart) docParts.get(i);
Variant value = null;

value = Dispatch.call(oWord, "Run", new
Variant("NewMacros.ParagraphBookmark"),new
Variant(d.paraStartIndex),new
Variant(d.paraEndIndex),new
Variant(document_directory+SOURCE_DOC_REF_WORD),new
Variant("BK_DP_"+tmpDpID));


This is code snapshot, "Dispatch.call(" is call for JACOB which actually uses native method to bookmark document paragraph.
I wanna know that if we call native method from java, does it wait for native to complete?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think so, but that's easy to test, no?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic