October 1999
Beginner
410 pages
10h 45m
English
The following example illustrates how to search for formatting (or formatted text). In this case, I search for any italicized text that is centered. As you can see, this is done by setting the corresponding formatting properties of the Find object (Font and ParagraphFormat) and then setting the Format property of the Find object to True. I must also not forget to clear the formatting first, so that only my formatting will be in effect. (By setting the Text property of the Find object to the empty string, all text is found.)
Selection.Find.ClearFormatting Selection.Find.Font.Italic = True Selection.Find.ParagraphFormat.Alignment = _ wdAlignParagraphCenter Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute
The following example searches for a particular style, in this case the Heading 1 style:
Selection.Find.ClearFormatting
Selection.Find.Style = _
ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.ExecuteRead now
Unlock full access