File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes General Computing and the fly likes Word Macros doesnt works when using JRun as a Service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Word Macros doesnt works when using JRun as a Service" Watch "Word Macros doesnt works when using JRun as a Service" New topic

Word Macros doesnt works when using JRun as a Service

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All,
Requirement Description: - My web application has a requirement of using a few rows of data from a .jsp page, and Merge them into an existing Word template.

I have developed an application using JRun Application/web server and Struts framework. I invoke the winword.exe file from my action class and pass the command line switches as the document filename and the macro name in order to do a word merge process.

Runtime rt = Runtime.getRuntime ();
String[] callAndArgs = strWordExePath,strWordTempName,"/mMacroName"};
Process child = rt.exec(callAndArgs);

The placeholders are in the template Word document. I have built a Macro, which contains the script for invoking the merge process with appropriate data source (.xls) file and saves the merged document in a specific folder in the server. Code for macro is as follows:-

Sub AutoExec()
Dim sName As String

Selection.HomeKey Unit:=wdStory
sName = ActiveDocument.Name
sName = Left(sName, Len(sName) - 9)
sPath = ActiveDocument.Path

ActiveDocument.MailMerge.OpenDataSource Name:= _
sPath & "\" & sName & ".xls" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="Entire Spreadsheet", SQLStatement _
:="", SQLStatement1:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
ActiveDocument.SaveAs FileName:=sPath & "\" & sName & ".doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
End Sub

The word merge process works fine and I could see the merged document in the concerned place, provided Jrun is running as an application (Admin & Default Server would be invoked from the Start button manually by a user every time the server starts).

Problem: - When the above process is repeated by making JRUN as a Service, the winword.exe hangs; instead of continuing with the request and opening the word document and running the macro for word merge process.
I can see winword.exe running in the Task Manager though. We tried capturing the exception but the control never returns back and the process never gets complete.

Is there some conflict happening with the two Applications (JRUN and MS Word 2000) when I start using JRUN as a service? What exactly changes when I change the Jrun from being an Application to exist as a service? Is there a better approach to achieve the above-mentioned objective?

I would greatly appreciate any help in this regard.

Also thanking in advance for all your time and patience in reading this.

Warm Regards,
I agree. Here's the link:
subject: Word Macros doesnt works when using JRun as a Service
Similar Threads
tomcat as service -> cannot start WINWORD.exe
Create pdf like word merge
Launching Microsoft word from Java application
Forms + VB macro communication problem with Java application deployed in Oralce Weblogic 11g server
SaxParserException: XML document structures must start and end within the same entity