Hi Phil,
As I said, you wouldn't want to use 'Application.DisplayAlerts = False' anyway. As for:
Quote:
Not sure what you mean about "programmatically make it a mailmerge main document " - How can you insert the fields where you want them without it being a MMerge document?
|
1. You would insert the SQL query code into the '.MailMerge.OpenDataSource' expression
2. You wouldn't need to - you can use your existing mailmerge main document (which is presumably defined via 'stDocName') if you simply convert it to an ordinary document. Indeed, you can insert mergefields into any document - it just won't function as a mailmerge document unless you do something to cause the document to behave as one.
Here's some sample code. I've included a comment with the full range of the 'OpenDataSource' expression's arguments (and a commented-out 'DisplayAlerts = False' line).
Code:
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim strMainDocNm As String
Dim strDataDocNm As String
Set wdApp = Word.Application
strMainDocNm = "C:\Users\PhilAJ\Documents\Temp\MailmergeMainDocument.doc"
strDataDocNm = "C:\Temp\abc.txt"
With wdApp
'.DisplayAlerts = False
.Application.Visible = True
Set wdDoc = .Documents.Open(Filename:=strMainDocNm)
With wdDoc
With .MailMerge
.MainDocumentType = wdFormLetters
'OpenDataSource(Name, Format, ConfirmConversions, ReadOnly, LinkToSource, _
AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, _
WritePasswordDocument, WritePasswordTemplate, Connection, _
SQLStatement, SQLStatement1, OpenExclusive, SubType)
.OpenDataSource Name:=strDataDocNm, LinkToSource:=True
.Execute
End With
.Close SaveChanges:=False
End With
End With