apply Method
Applies a style setting to a specified object.
expression.apply
expression Required. An expression that returns an IFPStyleState object.
Example
The following example inserts formatted text into the specified document, creates an IHTMLTxtRange object that includes the entire document, and then removes all formatting associated with the range. Then it inserts similarly formatted text directly below the first text inserted, creates a second IHTMLTxtRange object that again includes the entire document, and removes only text formatting associated with the range. The first paragraph inserted has all formatting removed, including paragraph formatting; the second paragraph retains its paragraph formatting but all text formatting is removed.
Sub ClearFormatting()
Dim objSS As IFPStyleState
Dim objDoc As FPHTMLDocument
Dim objPara As FPHTMLParaElement
Dim objRng As IHTMLTxtRange
Set objDoc = ActiveDocument
objDoc.body.innerHTML = "<p align=""center""><b><i><u>" & _
"<span style=""background-color: #0000FF"">Clears " & _
"all formatting; paragraph is no longer centered" & _
"</span></u></i></b></p>" & vbCrLf
Set objSS = objDoc.createStyleState
'Create the first text range.
Set objRng = objDoc.body.createTextRange
With objSS
.gather objRng
'Clear all formatting, including paragraph formatting.
.ClearAllFormatting
.Apply
End With
'Create the second text range.
objDoc.body.insertAdjacentHTML "beforeend", "<p align=" & _
"""center""><b><i><u>" & "<span style=""background" & _
"-color: #0000FF"">" & "Clears text formatting; " & _
"paragraph formatting remains</span></u></i></b></p>"
Set objRng = objDoc.body.createTextRange
With objSS
.gather objRng
'Clear only formatting that applies to text.
.ClearTextFormatting
.Apply
End With
Set objSS = Nothing
Set objDoc = Nothing
Set objRng = Nothing
End Sub