Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Styles.InUse not the same as styles that are in use 1

Status
Not open for further replies.

mintjulep

Technical User
Aug 20, 2004
1,551
JP
Reference thread68-1652782

VBA Help said:
Style(index).InUse Property
True if the specified style is a built-in style that has been modified or applied in the document or a new style that has been created in the document. Read-only Boolean.

Remarks
This property doesn't necessarily indicate whether the style is currently applied to any text in the document. For instance, if text that's been formatted with a style is deleted, the InUse property of the style remains True. For built-in styles that have never been used in the document, this property returns False.

So if you wanted a list of styles that are currently applied to text in a document how would you go about generating it?
 
You could use the Find method and a collection:

Code:
Dim sty As Style
Dim col As Collection

For Each sty In ActiveDocument.Styles
    With ActiveDocument.Range.Find
        .ClearFormatting
        .MatchWildcards = False
        .Text = ""
        .Style = sty
        .Execute
        If .Found Then
            col.Add sty.NameLocal
        End If
    End With
Next sty

You could of course also write the Style name into a text file or a Word document instead of building up a collection...
;-)

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top