Replacing text with field content

O

OrthoPod

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
 
D

Doug Robbins

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


--
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
 

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