Replace mergefields with form fields

J

jassi_Hayre

Hi All,

I'm kind of new to Word mailmerge, macros and vba. I currently have
problem where we have nearly 200 word templates that use mail merge
The data source is an Oracle8 database which is going to be scrapped.

I'd like to replace the mergefields on these templates with either for
fields or bookmarks programmaticaly.

Here's what i'd like to do in detail -

Search for a mergefield
Strip its name
Add a form field / bookmark where the mergefield is
Give this form field / bookmark the stripped out name.
Delete the mergefield

I'd like to use form fields instead of the merge fields because we ar
creating a vb application which should populate these fields instead o
a data source.

Any help would be appreciated.
Thanks
Ja
 
D

Doug Robbins

Given that there are problems with assigning names to formfields that are
inserted with VBA, I would suggest that you use docvariable fields instead
and have you vb application assign values to the variables.

The following code will replace the mergefields with docvariable fields of
the same name

Dim af As Field, fname As String, frange As Range
For Each af In ActiveDocument.Fields
If af.Type = wdFieldMergeField Then
Set frange = af.Code
fname = Trim(Mid(frange, 13))
frange = "Docvariable " & fname
End If
Next af
ActiveDocument.Fields.Update

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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