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. To use a StyleSheet class variable it first needs to be instantiated, for example
Dim sst as StyleSheet
Set sst = ActiveDocument.StyleSheets(Index:=1)
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
Delete
Deletes the specified cascading style sheet.
ActiveDocument.StyleSheets(1).Delete
FullName
Specifies the name of a cascading style sheet, including the drive or Web path.
Using this property is equivalent to using the Path, PathSeparator, and Name properties in sequence.
Sub CSSName()
MsgBox ActiveDocument.StyleSheets(1).FullName
End Sub
Index
Returns a Long that represents the position of an item in a collection.
Dim lngIndex As Long
lngIndex = ActiveDocument.StyleSheets(1).Index
Move
Moves a style sheet's order of precedence.
Move (Precedence)
Precedence: The precedence level.
ActiveDocument.StyleSheets(1).Move Precedence:=wdStyleSheetPrecedenceHigher
Name
Returns the name of the specified object.
Dim strName As String
strName = ActiveDocument.StyleSheets(1).Name
Path
Returns the disk or Web path to the specified style sheet.
The path doesn't include a trailing character—for example, "C:\MSOffice" or "https://MyServer". Use the PathSeparator property to add the character that separates folders and drive letters, and use the Name property to return the file name without the path.
Dim strPath As String
strPath = ActiveDocument.StyleSheets(1).Path
Title
Returns or sets a String representing the title of a Web style sheet.
Sub AssignCSSTitle()
ActiveDocument.StyleSheets.Item(1).Title = "New Look Stylesheet"
ActiveDocument.StyleSheets.Item(2).Title = "Standard Web Stylesheet"
ActiveDocument.StyleSheets.Item(3).Title = "Definitions Stylesheets"
End Sub
Type
Returns or sets the style sheet type. Possible return values are wdStyleSheetLinkTypeImported - Imported internal style sheet, wdStyleSheetLinkTypeLinked - Linked external style sheet.
ActiveDocument.StyleSheets(1).Type = wdStyleSheetLinkTypeImported