Wild card searching for a phrase

  • Thread starter Thread starter Elizabeth Baker
  • Start date Start date
E

Elizabeth Baker

I am trying to put an HTML tag either side of a section of text with bold
formatting. I would be very grateful if someone would let me know how I can
the wild card search to search for more than just a single word. /<b><*>/<b>
is presumably something like the necessary string for formatting, but I
would be very glad if someone would explain to me where I am going wrong.

Thank you in advance for your help.

Liz
 
Jay Freedman said:
See http://word.mvps.org/FAQs/General/UsingWildcards.htm, especially section
5 on searching for tags.

Dear Jay,

Thank you for your response. Unfortunately, I have already read the FAQ and
it doesn't solve my specific problem of wanting to search for text by
formatting and inserting a tag at either end. Or rather, if the FAQ does
solve my specific problem, I am unable to understand it. The latter is more
likely, unless my version of Word is unusual in using the * wildcard as
single words only.

If someone would be so kind as to post the strings I should be using (search
for text in bold and insert <b> in front and </b> at the end) I would be
very grateful.

Liz
 
Elizabeth said:
Dear Jay,

Thank you for your response. Unfortunately, I have already read the
FAQ and it doesn't solve my specific problem of wanting to search for
text by formatting and inserting a tag at either end. Or rather, if
the FAQ does solve my specific problem, I am unable to understand it.
The latter is more likely, unless my version of Word is unusual in
using the * wildcard as single words only.

If someone would be so kind as to post the strings I should be using
(search for text in bold and insert <b> in front and </b> at the end)
I would be very grateful.

Liz

I'm sorry, I misread your original post, thinking you already had tags and
wanted to search for them.

For the task you're doing, don't use wildcards (unless you need to use them
to limit the finds to specific patterns of text that also happen to be
bold). Use a normal find (.MatchWildcards = False), and set it up like this:

Sub TagBold()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False

.Format = True
.Text = ""
.Font.Bold = True
.Replacement.Text = "<b>^&</b>"
.Replacement.Font.Bold = False

.Execute Replace:=wdReplaceAll
End With
End Sub

Setting .Text = "" means it will find any contiguous area of text that
matches the required formatting (bold in this case), no matter how many
words it contains. The code ^& in the .Replacement.Text means "the found
text". I assume you want the bolding to be turned off in the replacement,
otherwise change that False to True.
 
Jay Freedman said:
For the task you're doing, don't use wildcards (unless you need to use them
to limit the finds to specific patterns of text that also happen to be
bold). Use a normal find (.MatchWildcards = False), and set it up like
this:

Jay,

Thank you very much for your help. Your macro will save me hours of work. I
shall edit it for use with other attributes.

Many thanks for taking the time to assist me. I appreciate you sharing your
expertise.

Liz
 
Back
Top