Recursive find and replace

S

Seamus Conlon

I am writing a macro to recursively find a word delimited
with | (eg |name|) and replace it with a string which I prompt
the user for. Any ideas on how best to do this.

Many thanks,
Seamus
 
D

Doug Robbins - Word MVP

This should do it:

Dim replacement As String
replacement = InputBox("Enter the replacement text", "Replacer")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="|[A-z]{1,}|", ReplaceWith:=replacement,
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With


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