Styles Collection Object
Word Developer Reference |
A collection of Style objects that represent both the built-in and user-defined styles in a document.
Remarks
Use the Styles property to return the Styles collection. The following example deletes all user-defined styles in the active document.
Visual Basic for Applications |
---|
|
Use the Add method to create a new user-defined style and add it to the Styles collection. The following example adds a new character style named "Introduction" and makes it 12-point Arial, with bold and italic formatting. The example then applies this new character style to the selection.
Visual Basic for Applications |
---|
|
Use Styles(Index), where Index is the style name, a WdBuiltinStyle constant or index number, to return a single Style object. You must exactly match the spelling and spacing of the style name, but not necessarily its capitalization. The following example modifies the font of the user-defined style named "Color" in the active document.
Visual Basic for Applications |
---|
|
The following example sets the built-in Heading 1 style to not be bold.
Visual Basic for Applications |
---|
|
The style index number represents the position of the style in the alphabetically sorted list of style names. Note that Styles(1)
is the first style in the alphabetical list. The following example displays the base style and style name of the first style in the Styles collection.
Visual Basic for Applications |
---|
|
The Styles object is not available from the Template object. However, you can use the OpenAsDocument method to open a template as a document so that you can modify styles in the template. The following example changes the formatting of the Heading 1 style in the template attached to the active document.
Visual Basic for Applications |
---|
|
Use the OrganizerCopy method to copy styles between documents and templates. Use the UpdateStyles method to update the styles in the active document to match the style definitions in the attached template.
See Also