clearTextFormatting Method

Microsoft FrontPage Visual Basic

expression.ClearTextFormatting

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

When you compare the ClearAllFormatting method with the ClearTextFormatting method, you notice that while the ClearAllFormatting method clears all formatting in the specified IHTMLTxtRange object, including paragraph formatting, the ClearTextFormatting method clears only formatting that modifies the appearance of text in the range.

Use the Apply method to apply the changes to the text range or element.

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 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
        
        'Clears 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