C
cherold
I have a little macro to replace certain HTML tags in a document to a
special format. Since I don't know VB, I just recording a macro and
then cut and paste the code with different parameters, and when I
discover something new I need to replace I do another cut and paste.
But the ex-programmer in me hates such clunky code, so I was hoping
someone could tell me how to create a text replacement look, in which
I could create some sort of array of pairs like
( ("[A HREF=", "[LINK]") ("<P>", "[P"]) ("</P>", "[/P]) ("<BR>",
""))
and then loop through that array, putting the snippet of code I've
been using inside a loop that goes through each pair of the array.
This is the code I have below. As you can see, I just need to change
the .Text and .Replacement.Text variable for each replacement. Thanks
for any help.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "<p><br>^p</p>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
special format. Since I don't know VB, I just recording a macro and
then cut and paste the code with different parameters, and when I
discover something new I need to replace I do another cut and paste.
But the ex-programmer in me hates such clunky code, so I was hoping
someone could tell me how to create a text replacement look, in which
I could create some sort of array of pairs like
( ("[A HREF=", "[LINK]") ("<P>", "[P"]) ("</P>", "[/P]) ("<BR>",
""))
and then loop through that array, putting the snippet of code I've
been using inside a loop that goes through each pair of the array.
This is the code I have below. As you can see, I just need to change
the .Text and .Replacement.Text variable for each replacement. Thanks
for any help.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "<p><br>^p</p>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll