MailMerge destination document

A

Alex

Hi everyone

I've created a mailmerge template for my work colleges
that when opened automatically runs the following code.

Sub autonew()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End Sub

However, end users being end users, they still aren't
satisfied, so I hope you guys can help.

Requirements:
The macro must run on Word 97, 2000, XP and 2003
The Full Recipient list will always be merged into the
document

Problem with Current Code:
Even though the current code does all the hard work for
them, they don't like the fact that it produces two
documents, The document with MailMerge fields and the
Merged document.

I've been through the VBA object model and the only
destination options appear to be:

1. wdSendToNewDocument
2. wdSendToFax
3. wdSendToEmail
4. wdSendToPrinter

So the question is, is there any way via VBA to force word
to merge the recipient list data into the first document
created by Word, that way only one document is produced
instead of two.

A big thank you in advance

Alex
 
P

Peter Jamieson

Try something more like:

Sub autonew()
Dim oMainDocument As Word.Document
Set oMainDocument = ActiveDocument
With oMainDocument.MailMerge
.Destination = wdSendToNewDocument
' I don't think you need the following
' .MailAsAttachment = False
' .MailAddressFieldName = ""
' .MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
oMainDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
 
A

Alex

Thanks Peter

That worked great.

Alex
-----Original Message-----
Try something more like:

Sub autonew()
Dim oMainDocument As Word.Document
Set oMainDocument = ActiveDocument
With oMainDocument.MailMerge
.Destination = wdSendToNewDocument
' I don't think you need the following
' .MailAsAttachment = False
' .MailAddressFieldName = ""
' .MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
oMainDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

--
Peter Jamieson - Word MVP
Word MVP web site http://word.mvps.org/




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top