View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

I am writing an application that will accept pipe "|" delimited text files
from other applications to be mail merged when receive. I can pick the files
up from the directory, open the main mail document and open the data source;
however when the opendatasource command is executed a dialog box pops up
asking "Text File Connection Properties". I need to pass all the information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile