Class StyleSheet (Word VBA)

The class 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.

The main procedures of class StyleSheet are Delete and StyleSheets.Add


To use a StyleSheet class variable it first needs to be instantiated, for example

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

The following procedures can be used to set variables of type StyleSheet: StyleSheets.Add, StyleSheets.Item and Document.StyleSheets

For Each

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

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


The following procedures in this class have been grouped together and are described on a separate theme page

Name with its procedures FullName and Name


These are the main methods of the StyleSheet class

Delete - Deletes the specified cascading style sheet.


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

Dim strFileName As String: strFileName = 
Dim strTitle As String: strTitle =  
Dim sst As StyleSheet
Set sst = ActiveDocument.StyleSheets.Add(FileName:=strFileName, LinkType:=wdStyleSheetLinkTypeImported, Title:=strTitle, Precedence:=wdStyleSheetPrecedenceHigher)


Index returns a Long that represents the position of an item in a collection.

Dim lngIndex As Long
lngIndex = ActiveDocument.StyleSheets(1).Index

Parent returns an object that represents the parent object of the specified StyleSheet object.

Dim objParent As Object
Set objParent = ActiveDocument.StyleSheets(1).Parent

Path returns the disk or Web path to the specified style sheet.

Dim strPath As String
strPath = ActiveDocument.StyleSheets(1).Path

Title returns or sets a String representing the title of a Web style sheet.

ActiveDocument.StyleSheets(1).Title =

Type returns or sets the style sheet type.

ActiveDocument.StyleSheets(1).Type = wdStyleSheetLinkTypeImported

StyleSheets.Count returns a Long that represents the number of style sheets in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.StyleSheets.Count

StyleSheets.Parent returns an object that represents the parent object of the specified StyleSheets object.

Dim objParent As Object
Set objParent = ActiveDocument.StyleSheets.Parent