StyleSheet Object

Microsoft Word Visual Basic

StyleSheet Object

         
StyleSheets StyleSheet

Represents a single cascading style sheet attached to a web document. The StyleSheet object is a member of the StyleSheets collection. The StyleSheets collection contains all the cascading style sheets attached to a specified document.

Using the StyleSheet object

Use the Item method or StyleSheets(index), where index is the name or number of the style sheet, of the StyleSheets collection to return a StyleSheet object. The following example removes the second style sheet from the StyleSheets collection.

Sub WebStyleSheets()
    ActiveDocument.StyleSheets.Item(2).Delete
End Sub

Use the Index property to determine the precedence of cascading style sheets. The following example creates a table of attached cascading style sheets, ordered and indexed according to which style sheet is most important.

Sub CSSTable()
    Dim styCSS As StyleSheet

    With ActiveDocument.Range(Start:=0, End:=0)
        .InsertAfter "CSS Name" & vbTab & "Index"
        .InsertParagraphAfter
        For Each styCSS In ActiveDocument.StyleSheets
            .InsertAfter styCSS.Name & vbTab & styCSS.Index
            .InsertParagraphAfter
        Next styCSS
        .ConvertToTable
    End With
End Sub

Use the Move method to reorder the precedence of attached style sheets. The following example moves the most important style sheet to the least important of all attached cascading style sheets.

Sub MoveCSS()
    ActiveDocument.StyleSheets(1) _
        .Move wdStyleSheetPrecedenceLowest
End Sub