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 / September 2004

Tip: Looking for answers? Try searching our database.

Replacing text with field content

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
OrthoPod - 09 Sep 2004 17:52 GMT
I have several thousand documents from which I want to remove the
identifying names in the text. For each document, I can easily
identify the relevant name programatically (it always occurs in the
same place in the document), but subsequent occurances are randomly
placed.
   I have tried to do this by making the initial name occurance a
bookmark, and then enter that in the Find & Replace dialogue, but I
can't seem to find a way to get the F&R to read the field-name (in
{}'s ) as a variable rather than a literal string.
   Since I am new to writing VBA, I am probably missing something
painfully obvious. Any help/advice anyone can give me would be much
appreciated.

Thanks,
JM
Doug Robbins - 10 Sep 2004 00:33 GMT
If you have the code to locate and select the name, the following will
delete all occurences of it in the document:

Dim mystr As String
mystr = Selection.Text
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:=mystr, MatchWildcards:=False,
Replacewith:="", Wrap:=wdFindContinue, Forward:=True, Replace:=wdReplaceAll)
= True
   Loop
End With

To set up a batch process to handle all of the documents, see the article
"Find & ReplaceAll on a batch of documents in the same folder" at:

http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

>I have several thousand documents from which I want to remove the
> identifying names in the text. For each document, I can easily
[quoted text clipped - 11 lines]
> Thanks,
> JM
Jim Michelson - 10 Sep 2004 16:15 GMT
Thanks. This looks like it should do what I want. I'll let you know.

Jim

> If you have the code to locate and select the name, the following will
> delete all occurences of it in the document:
[quoted text clipped - 14 lines]
>
> http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

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.