Word Merge gives problems when I run the application server as a Service

N

nc

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);
child.waitFor();

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, _
SaveAsAOCELetter:=False
ActiveWindow.Close
ActiveDocument.Save
ActiveDocument.Close
Application.Quit
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,
Nitin
 
P

Peter Jamieson

Here's my previous answer again:

There is probably a security-related problem as the chances are that your
service is running under a different user name. However, that's about all I
know about it - you'll robably find more useful info at

PRB: Error 800A175D - Could Not Open Macro Storage
http://support.microsoft.com/default.aspx?scid=kb;en-us;224338

and the general article referenced there:
INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/default.aspx?kbid=257757:

--
Peter Jamieson
MS Word MVP

nc said:
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);
child.waitFor();

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, _
SaveAsAOCELetter:=False
ActiveWindow.Close
ActiveDocument.Save
ActiveDocument.Close
Application.Quit
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,
Nitin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top