It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

VB cluster repeats

Moderator: dafunkymunky

VB cluster repeats

Postby sefir on Thu Sep 04, 2008 7:06 pm

My question may be a bit unsophisticated for this forum. If so, I apologize.

If I want to build a VB macro that changes a few dozen words in a document into some other words, do I have to repeat the following cluster for every word on my list? Is there a way of reducing the length of the macro? Thank you for the help.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.ColorIndex = wdBlue
With Selection.Find
.Text = "JACK"
.Replacement.Text = "JILL"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.ColorIndex = wdBlue
With Selection.Find
.Text = "TOM"
.Replacement.Text = "BILL"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
sefir
 
Posts: 0
Joined: Thu Sep 04, 2008 6:45 pm

Who is online

Users browsing this forum: No registered users and 2 guests