Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Andrew Andrew is offline
external usenet poster
 
Posts: 48
Default Server Automation for Word

Hi, I am running into problem when I try to turn my mailmerge automation code
over to the server. My mailmerge code works just fine when being called from
the client workstation (only it is slow like hell and cannot do multiple
documents) I decide to switch the call to the server, which is more powerful
and hopefully can solve the slowness issue. Here's the code.

Public Function CreateWordDocument(ByVal fileName As String, _
ByVal templateName As String, ByVal sourceData As DataSet, _
ByVal workingDirectory As String, ByVal key As Guid) As
MSWord.Document


Dim mergedDoc As MSWord.Document
Dim wrdDoc As MSWord.Document
' Write the Datasource Text File keyDS.txt
Me.FillTable(sourceData, workingDirectory, key)
Me.Application.Visible = True
wrdDoc = Me.AddWordDocument(templateName, False)
wrdDoc.ActiveWindow.Visible = True
wrdDoc.Select()

'Attach DataSource and Perform mail merge if there is any data
If (sourceData.Tables.Count 0) Then
If (sourceData.Tables(0).Rows.Count 0) Then
With wrdDoc.MailMerge

..OpenDataSource(Name:=Me.ConstructFileName(workin gDirectory, key))
End With

Me.PerformMailMerge(wrdDoc)
End If
End If

'Whether a mail merge happen or not, the active document will be the
mergedDoc
mergedDoc = Me.Application.ActiveDocument
mergedDoc.ActiveWindow.Visible = True
mergedDoc.SaveAs(fileName)

'Close the template from documents
If Not (wrdDoc Is mergedDoc) Then
wrdDoc.Close(False)
End If
wrdDoc = Nothing
mergedDoc.ActiveWindow.Visible = True
Me._fileName = mergedDoc.FullName
MSWordApplication.ToggleSaveAs(Me.Application, False)
Return mergedDoc

End Function

As soon as the code run to the line where it actually uses the Word object,
e.g.: wrdDoc.ActiveWindow.Visible = True
It will give the fatal exception error of a null object reference.

Now I have read the kb257757 and tried what says in KB288366 and KB288367 to
configure Office application to run under the interactive user account /
specific user account and to no avail. I need help desperately.
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Server Automation for Word

Clearly if you try to run Word in a server environment then you're on your
own as kb257757 says.

If you start with a completely blank Word document/template, do you get
beyond

wrdDoc = Me.AddWordDocument(templateName, False)


? If not, I'd say it's a general Word server-side configuration issue and I
certainly can't help you either (i.e., search Google groups and maybe you'll
find the answer).

If that works OK, then I'd guess that the problem is that your template
already has a data source attached and
a. either it is not finding it and trying to display a dialog box on the
server to prompt the user for the data source location or
b. on your workstation, Word uses a text converter to open the data source,
and that converter is not installed on the server (or some such). Seems
unlikely. Or
c. you need to take account of
"Opening This Will Run the Following SQL Command" Message When You Open a
Word Document"
at
http://support.microsoft.com?kbid=825765

In case (a) the solution is likely to be to disconnect your
document/template from the data source before saving it on the server.

Personally I wouldn't expect running the merge on a server to make much
difference unless the workstation is really small and feeble. If you are
running the merge against large numbers of records it may make no
difference - you could try running "one merge per record" (search this group
on Google groups for "jamieson activerecord" for a way to do that) or "one
merge per n records". Also, does it run any faster if you experimentally
reduce the size and complexity of the mail merge main document? If so, there
may be something in that document that makes Word slow down such as a
formatted bullet.

Peter Jamieson
"Andrew" wrote in message
...
Hi, I am running into problem when I try to turn my mailmerge automation
code
over to the server. My mailmerge code works just fine when being called
from
the client workstation (only it is slow like hell and cannot do multiple
documents) I decide to switch the call to the server, which is more
powerful
and hopefully can solve the slowness issue. Here's the code.

Public Function CreateWordDocument(ByVal fileName As String, _
ByVal templateName As String, ByVal sourceData As DataSet, _
ByVal workingDirectory As String, ByVal key As Guid) As
MSWord.Document


Dim mergedDoc As MSWord.Document
Dim wrdDoc As MSWord.Document
' Write the Datasource Text File keyDS.txt
Me.FillTable(sourceData, workingDirectory, key)
Me.Application.Visible = True
wrdDoc = Me.AddWordDocument(templateName, False)
wrdDoc.ActiveWindow.Visible = True
wrdDoc.Select()

'Attach DataSource and Perform mail merge if there is any data
If (sourceData.Tables.Count 0) Then
If (sourceData.Tables(0).Rows.Count 0) Then
With wrdDoc.MailMerge

.OpenDataSource(Name:=Me.ConstructFileName(working Directory, key))
End With

Me.PerformMailMerge(wrdDoc)
End If
End If

'Whether a mail merge happen or not, the active document will be
the
mergedDoc
mergedDoc = Me.Application.ActiveDocument
mergedDoc.ActiveWindow.Visible = True
mergedDoc.SaveAs(fileName)

'Close the template from documents
If Not (wrdDoc Is mergedDoc) Then
wrdDoc.Close(False)
End If
wrdDoc = Nothing
mergedDoc.ActiveWindow.Visible = True
Me._fileName = mergedDoc.FullName
MSWordApplication.ToggleSaveAs(Me.Application, False)
Return mergedDoc

End Function

As soon as the code run to the line where it actually uses the Word
object,
e.g.: wrdDoc.ActiveWindow.Visible = True
It will give the fatal exception error of a null object reference.

Now I have read the kb257757 and tried what says in KB288366 and KB288367
to
configure Office application to run under the interactive user account /
specific user account and to no avail. I need help desperately.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Office licensing on terminal server Brian Microsoft Word Help 2 May 5th 06 08:40 PM
Word slow to open after retiring template server GeorgeJetson Microsoft Word Help 2 April 26th 06 06:25 AM
mail merge documents moved from one server to another server don't Derek Ruesch Mailmerge 0 September 8th 05 06:36 PM
Server Change Affecting Mail Merge Macros Victor Lazlo Mailmerge 1 May 20th 05 02:10 PM
Running document macro from server Intravler New Users 0 March 4th 05 04:33 AM


All times are GMT +1. The time now is 11:54 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"