Help with Find and Replace Wildcards

J

James Walker

Greetings,

I just recently found out about using Wildcards in words Find and Replace
but not having much luck using them.

I'm trying to do two different things:
1) Any line that starts with 2005 needs to be bold
2) Any line that contains a hyphen needs a font size of 8

I know I will need to do a Find and Replace for each item, but I'm not
having luck with creating the wildcard string. Any help would be greatly
appreciated.

Thanks,
James Walker, Jr.
 
D

Doug Robbins - Word MVP

The following macro will do the first one - note, you don't need wildcards
for this. However, you need to realise that when the bold font is applied,
the text may no longer all fit on the one line.

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="2005", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
If Selection.Range.Start = Selection.Bookmarks("\line").Range.Start
Then
Selection.Bookmarks("\line").Range.Bold = True
End If
Selection.Collapse wdCollapseEnd
Loop
End With

And, the following will change the font size for lines containing a hyphen.
Once again, you don't need wildcards, but when you reduce the font, you may
change the linebreaks.

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="-", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
Selection.Bookmarks("\line").Range.Font.Size = 8
Selection.Collapse wdCollapseEnd
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
 
K

Klaus Linke

Hi James,

Maybe the macros by Doug will do the trick?
Since a line will probably break differently when you make part of it bold,
or change the font size, you may really mean paragraphs?

It would probably be better to assign a style that's bold (or 8 pt) instead
of manual formatting.

1) If "2005" isn't likely to appear anywhere but at the start of a
paragraph, you could do a wildcard search for "2005[!^13]@^13".
Else, you could replace (using wildcards) ^132005 with ^13$$2005, then do a
second search to apply the bold style to all paragraphs containing $$ (Find
what: $$, Replace with: ^& plus that style), and finally remove $$ (replace
with nothing).
(BTW, I have suggested that Word should have wildcard anchors for the start
and end of a paragraph. You might make such a suggestion to MS also. Then
you'd only need one find/replace for this.)

2) Simply put the hyphen in "Find what", and the 8 pt paragraph style in
"Replace with", in a regular find/replace without wildcards.
Or you could replace the hyphen with "Format > Paragraph > Alignment:
Center", and then replace that center alignment with Font size 8 pt and
alignment=left in a second replacement (... if you don't have centered
paragraphs).

Regards,
Klaus
 

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