gatherFromElement Method

Microsoft FrontPage Visual Basic

expression.GatherFromElement(element)

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

element    Required IHTMLElement object. The element associated with a given style.

Example

The following example inserts two heading elements and gathers the style properties from the first heading element stored 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
        .textTransform = "uppercase"
        .applyToElement objHeading2
    End With

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