View Single Post
  #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.