applyToElement Method

Microsoft FrontPage Visual Basic

object to a specified element.

expression.applyToElement(element)

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

element    Required IHTMLElement object. The name of the element that you want to apply a given style property to.

Example

The following example gathers style properties from an element, as specified in the objHeading1 variable. It then creates an IFPStyleState object, which is stored in the objSS variable, modifies the style properties, and then applies the modified style properties to the element stored in the objHeading2 variable.

Sub ApplyStyleToElement()
    Dim objSS As IFPStyleState
    Dim objHeading1 As IHTMLElement
    Dim objHeading2 As IHTMLElement

    ActiveDocument.body.innerHTML = "<H1>This is line 1</H1>" _
        & vbCrLf & "<H1>This is line 2</H1>"
    
    Set objHeading1 = ActiveDocument.all.tags("h1").Item(0)
    Set objHeading2 = ActiveDocument.all.tags("h1").Item(1)
        
    Set objSS = ActiveDocument.createStyleState
    
    With objSS
        .GatherFromElement objHeading1
        .fontFamily = "Arial"
        .Color = vbRed
        .textAlign = "right"
        .setProperty "background-color", vbBlue
        .textDecorationBlink = True
        .textDecorationLineThrough = True
        .textDecorationOverline = True
        .textDecorationUnderline = True
        .textTransform = "uppercase"
        .applyToElement objHeading2
    End With

    Set objSS = Nothing
    Set objHeading1 = Nothing
    Set objHeading2 = Nothing
End Sub