Class StyleSheets (Word VBA)

A collection of StyleSheet objects that represents the cascading style sheets attached to a document. The StyleSheets collection includes all cascading style sheets displayed in the Linked CSS Style Sheets dialog box. To use a StyleSheets class variable it first needs to be instantiated, for example


Dim sss as StyleSheets
Set sss = ActiveDocument.StyleSheets

For Each

Here is an example of processing the StyleSheets items in a collection.


Dim sst As StyleSheet
For Each sst In ActiveDocument.StyleSheets
	
Next sst

Add

Returns a StyleSheet object that represents a new style sheet added to a web document.

Add (FileName, LinkType, Title, Precedence)


Sub NewStylesheet() 
 ActiveDocument.StyleSheets.Add _ 
 FileName:="c:\WebSite.css", _ 
 Precedence:=wdStyleSheetPrecedenceHighest, _ 
 LinkType:=wdStyleSheetLinkTypeLinked, _ 
 Title:="Test Stylesheet" 
End Sub

Arguments

The following arguments are required:

FileName (String) - The path and file name of the cascading style sheet.

LinkType (WdStyleSheetLinkType) - Indicates whether the style sheet should be added as a link or imported into the web document.

Possible return values are wdStyleSheetLinkTypeImported - Imported internal style sheet, wdStyleSheetLinkTypeLinked - Linked external style sheet.

Title (String) - The name of the style sheet.

Precedence (WdStyleSheetPrecedence) - Indicates the level of importance compared with other cascading style sheets attached to the web document.


Possible values are

wdStyleSheetPrecedenceHigher Raise precedence.
wdStyleSheetPrecedenceHighest Highest precedence.
wdStyleSheetPrecedenceLower Lower precedence.
wdStyleSheetPrecedenceLowest Lowest precedence.

Count

Returns a Long that represents the number of style sheets in the collection.


Dim lngCount As Long
lngCount = ActiveDocument.StyleSheets.Count

Item

Returns an individual StyleSheet object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.


Dim sst As StyleSheet
Set sst = ActiveDocument.StyleSheets(Index:=1)