Mail Merge

ANGanley

New member
Local time
Today, 18:43
Joined
Oct 8, 2007
Messages
2
I am creating a mail merge document using the following code extract.


' Create a data source at C:\template.doc that contains the field data.
wrdDoc.MailMerge.CreateDataSource(Name:="C:\template.doc", _
HeaderRecord:="FirstName, LastName, Address, Postcode, email)

I then use the following code to,

' Creates a new word document & inserts the merged data.
wrdSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
wrdMergeFields = wrdMailMerge.Fields
wrdMergeFields.Add(wrdSelection.Range, "FirstName")
wrdSelection.TypeText(" ")
wrdMergeFields.Add(wrdSelection.Range, "LastName")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "Address")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "Postcode")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "email")



This then sets up the mereged data as follows then populates the fields.

«FirstName» «LastName»
«Address»
«Postcode»
«email»

Here’s the question.
I need to modify the code so that the user is able to select & use their own templates.

Eg.

User1’s template migth look like.


«FirstName» «LastName»
«Address»
«Postcode»

User2’s template might look like.

«FirstName» «LastName»
«Address»
«email»

Is there an option eg wrd.selection ?????? that I can use to only populate the fields I want.

I have tried.

wrdMergeFields.Add(wrdSelection.Range, "«FirstName»")
wrdSelection.TypeText(" ")
wrdMergeFields.Add(wrdSelection.Range, "«LastName»")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "«Address»")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "«Postcode»")
wrdSelection.TypeParagraph()
wrdMergeFields.Add(wrdSelection.Range, "«email»")

but it doed not work.
 
' Perform mail merge.
wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
 

Users who are viewing this thread

Back
Top Bottom