Replacing Merge Fields

D

Dominic Godin

Hi,

I am writing some software that updates clients' data to the new version of
our product. Part of this data contains many thousand Word templates with
MailMergeDataFields. These fields need to be replaced with the new
corresponding fields.

I can use the:

WordDoc.MailMerge.DataSource.DataFields.Item(index).Name

to get all the merge fields held within a document but this field is read-
only so I can't update it.

I have tried using the Find.Execute to search and replace these fields but
this doesn't work either. Any body no how this can be done?

Thanks

Dominic Godin
 
D

Doug Robbins - Word MVP

Use the following to change the mergefield names in the mailmerge main
documents:

Dim amf As Field, fcode As Range, i As Integer, j As Integer
For Each amf In ActiveDocument.Fields
Set fcode = amf.Code
i = InStr(fcode, Chr(34))
j = InStr(Mid(fcode, i + 1), Chr(34))
fcode.Start = fcode.Start + i
fcode.End = fcode.Start + j - 1
Select Case fcode
Case "Fname"
fcode.Text = "FirstName"
Case "Lname"
fcode.Text = "LastName"
End Select
Next amf
ActiveDocument.Fields.Update


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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