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 / August 2005

Tip: Looking for answers? Try searching our database.

Is it possible to use find replace for Merge Field data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris - 22 Aug 2005 03:51 GMT
In order to speed up setup of a word doc that is a long contract, can I use
find replace to insert the mergefield I want into the document.

Eg. Mergfield={ CMDHB } replacing text in doc XDHB

Hope this makes sense? or is there another way I can do this (I am not very
VB literate)

Thanks
Doug Robbins - 22 Aug 2005 15:58 GMT
If there is a consistent pattern to what you want to replace - e,g, all text
that is to be replaced with a merge field begins with an uppercase X and the
letters in the text are all in uppercase and the corresponding mergefield
has the X replaced by CM, then it should be possible using code such as the
following:

Dim drange As Range, dfield As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="X[A-X]{1,}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
       Set drange = Selection.Range
       dfield = "CM" & Mid(drange, 2)
       ActiveDocument.Fields.Add Range:=drange, Type:=wdFieldMergeField,
Text:=dfield
   Loop
End With

Signature

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

> In order to speed up setup of a word doc that is a long contract, can I
> use
[quoted text clipped - 7 lines]
>
> Thanks

Rate this thread:






 
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.