FindStyle Method

Searches for a style in the style collection of the document. Returns the index of the specified style in the style collection of the document.

Applies to: Document object

Syntax

[[Set] indexRet =] object.FindStyle ( styleObj )

The FindStyle method syntax has these parts:

Part Description
object Required. An expression, that returns an instance of the Document object.
styleObj Required. An expression, that returns an instance of the Style object. Specified the style, which index is to be returned.
indexRet Optional Long.

Remarks

If the specified style was not found in the style collection of the document, the FindStyle method returns 0.

Example

This example contains a document-level script. It uses the FindStyle method to demonstrate that a new style is added to the end of the style collection of the document. Two new styles are added, and then their indices are displayed. The index of the last style added is equal to the number of styles in the document.

' Declare variables
Dim new_style1 As Style
Dim new_style2 As Style
Dim index1 As Long
Dim index2 As Long

' Add two new styles
Set new_style1 = thisDoc.AddStyle("New_Style_1")
Set new_style2 = thisDoc.AddStyle("New_Style_2")

TRACE new_style1
TRACE new_style1

' Get indices of the added styles
Let index1 = thisDoc.FindStyle( new_style1 )
Let index2 = thisDoc.FindStyle( new_style2 )

' Display the indices to make sure 
' that the index of the style added first is less
' than the index of the second added style
TRACE "index1 = " & index1
TRACE "index2 = " & index2

 

See Also

AddStyle method, RemoveStyle method, RemoveStyleByName method, RenameStyle method, Style method, StyleByName method, StylesNum method, Style object