Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / July 2006

Tip: Looking for answers? Try searching our database.

Server Automation for Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 13 Jul 2006 21:09 GMT
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(workingDirectory, 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.
Peter Jamieson - 14 Jul 2006 03:29 GMT
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
> Hi, I am running into problem when I try to turn my mailmerge automation
> code
[quoted text clipped - 59 lines]
> configure Office application to run under the interactive user account /
> specific user account and to no avail.  I need help desperately.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.