Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Help with Find and Replace Wildcards

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Walker - 19 Jan 2006 21:13 GMT
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.
Doug Robbins - Word MVP - 19 Jan 2006 22:13 GMT
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

Signature

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

> Greetings,
>
[quoted text clipped - 11 lines]
> Thanks,
> James Walker, Jr.
Klaus Linke - 19 Jan 2006 23:06 GMT
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

> Greetings,
>
[quoted text clipped - 11 lines]
> Thanks,
> James Walker, Jr.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.