Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / June 2004

Tip: Looking for answers? Try searching our database.

Insert a MailMerge field into a template

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 03 Jun 2004 20:27 GMT
I have a problem I need a solution for.  I need to open up
a template file and search for some text and replace the
text with a mailmerge field.  The field does not exsist in
the mailmerge field drop down list so I don't know if this
is an issue.  So using vb I need to grab the text in the
template search for some key text and replace it with the
text representation needed to include a mailmerge field
and save the doc.

Mike
Doug Robbins - Word MVP - 03 Jun 2004 23:14 GMT
It will be an issue if you try and execute the merge.

The following code will insert a mergefield with the name of TheFieldName in
place of every instance of the word TheWord:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="TheWord", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
       ActiveDocument.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, Text:= _
       "MERGEFIELD  TheFieldName ", PreserveFormatting:=True
   Loop
End With

Signature

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

> I have a problem I need a solution for.  I need to open up
> a template file and search for some text and replace the
[quoted text clipped - 6 lines]
>
> Mike
Mike - 04 Jun 2004 16:04 GMT
Thanks Doug this is the third time you have helped me.

So when you say "It will be an issue if you try and
execute the merge" does that relate to the "The field does
not exsist in the mailmerge field drop down list "? If so
is there a way to add a MailMerge field to the drop down
list using vb so I can do a merge?  The data file used for
this merge will contain the new merge field.

Mike
>-----Original Message-----
>It will be an issue if you try and execute the merge.
[quoted text clipped - 25 lines]
>
>.
Doug Robbins - Word MVP - 04 Jun 2004 23:53 GMT
Hi Mike,

Yes, it did relate to the field not being in the drop down list of
mergefields in the datasource.

If the field is not in the datasource, from where is the information going
to come?

If the field is in the datasource, then it should appear in the list of
available mergefields.

Signature

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

> Thanks Doug this is the third time you have helped me.
>
[quoted text clipped - 53 lines]
> >
> >.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.