• Post Reply Bookmark Topic Watch Topic
  • New Topic

Word Macros doesnt works when using JRun as a Service  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!