Share via


StyleSheet Object

Word Developer Reference

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.

Remarks

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.

Visual Basic for Applications
  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.

Visual Basic for Applications
  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.

Visual Basic for Applications
  Sub MoveCSS()
    ActiveDocument.StyleSheets(1) _
        .Move wdStyleSheetPrecedenceLowest
End Sub

See Also