expression.ClearFormatting
expression Required. An expression that returns one of the objects in the Applies To list.
Remarks
To ensure that formatting isn't included as criteria in a find or replace operation, use this method before carrying out the operation.
Example
As it applies to the Selection object.
This example removes all text and paragraph formatting from the active document.
Sub ClrFmtg()
ActiveDocument.Select
Selection.ClearFormatting
End Sub
This example removes all text and paragraph formatting from the second through the fourth paragraphs of the active document.
Sub ClrFmtg2()
ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(2).Range.Start, _
End:=ActiveDocument.Paragraphs(4).Range.End).Select
Selection.ClearFormatting
End Sub
As it applies to the Replacement object.
This example clears formatting from the find or replace criteria before replacing the word "Inc." with "incorporated" throughout the active document.
Sub ClrFmtgReplace()
Dim rngTemp As Range
Set rngTemp = ActiveDocument.Content
With rngTemp.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWholeWord = True
.Execute FindText:="Inc.", ReplaceWith:="incorporated", _
Replace:=wdReplaceAll
End With
End Sub
As it applies to the Find object.
This example removes formatting from the find criteria before searching through the selection. If the word "Hello" with bold formatting is found, the entire paragraph is selected and copied to the Clipboard.
Sub ClrFmtgFind()
With Selection.Find
.ClearFormatting
.Font.Bold = True
.Execute FindText:="Hello", Format:=True, Forward:=True
If .Found = True Then
.Parent.Expand Unit:=wdParagraph
.Parent.Copy
End If
End With
End Sub