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 / Long Documents / June 2005

Tip: Looking for answers? Try searching our database.

[vba] search and format finds

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
leaftye - 24 Jun 2005 19:28 GMT
I'm trying to create a procedure that searches for certain words and
then formats those words.  Two problems:
1. If I have a word(s) highlighted when I start the macro, it formats
the selection...even though it hasn't found anything yet.
2. It finds the first word, but not the rest.  

Please help me figure out what I'm doing wrong. Here's my code:

Code:
--------------------
   
 With Selection
 With .Find
 .ClearFormatting
 .Text = "access"
 .MatchCase = False
 .MatchWholeWord = True
 .Execute
 .ClearFormatting
 End With
 .FormattedText.Case = wdTitleWord
 .Font.Underline = wdUnderlineSingle
 End With
 
 With Selection
 With .Find
 .ClearFormatting
 .Text = "assignment"
 .MatchCase = False
 .MatchWholeWord = True
 .Execute
 .ClearFormatting
 End With
 .FormattedText.Case = wdTitleWord
 .Font.Underline = wdUnderlineSingle
 End With
 
--------------------

Signature

leaftye

Doug Robbins - 25 Jun 2005 06:52 GMT
Here's how to do it:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="access", MatchWildcards:=False,
MatchCase:=False, _
MatchWholeWord:=True, Wrap:=wdFindStop, Forward:=True) = True
       Selection.Range.Case = wdTitleWord
   Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
   Do While .Execute(FindText:="assignment", MatchWildcards:=False,
MatchCase:=False, _
MatchWholeWord:=True, Wrap:=wdFindStop, Forward:=True) = True
       Selection.Range.Case = wdTitleWord
   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

>
> I'm trying to create a procedure that searches for certain words and
[quoted text clipped - 35 lines]
>
> --------------------

Rate this thread:






 
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.