Re: Select words with specific attributes/color

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Helmut Weber (elmkqznfwvccbf_at_mailinator.com)
Date: 01/22/05


Date: Sat, 22 Jan 2005 23:19:33 +0100

Hi Hari,
probably, you are looking for something like this:

Sub Makro17()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
resetsearch
With rTmp.Find
  .Text = "<Sub>"
  .MatchWildcards = True
   While .Execute
      rTmp.Select
      Selection.Bookmarks("\para").Select
      Selection.Font.Bold = True
  Wend
End With
resetsearch
End Sub

Public Sub ResetSearch()
With Selection.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = ""
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindContinue
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
   ' plus some more
   .Execute
End With
End Sub

Which means:

reset search options
search for "sub" as a whole word,
select the paragraph it is in,
format the selection as bold
reset search options

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/



Relevant Pages