Style Count in Word 2003

A

Amish

Can someone tell me how I can determine how many times a style occurs
a document?

I'm trying to write a macro, but I would like to use the value that
Word displays when I view the style list (it tells me I can select all
12 instances, for example).

Thank you.
 
D

Doug Robbins - Word MVP

Use the following, substituting the style that you want for Heading 1

Dim i As Long
i = 0
Selection.HomeKey wdStory
Selection.Find.Style = "Heading 1"
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
i = i + 1
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
Loop
End With
MsgBox "There are " & i & " instances of the Heading 1 style in the
document."


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
A

Amish

Thanks Doug.

Use the following, substituting the style that you want for Heading 1

Dim i As Long
i = 0
Selection.HomeKey wdStory
Selection.Find.Style = "Heading 1"
With Selection.Find
    Do While .Execute(FindText:="", Forward:=True, _
        MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
        i = i + 1
        Selection.Collapse wdCollapseEnd
        Selection.MoveRight wdCharacter, 1
    Loop
End With
MsgBox "There are " & i & " instances of the Heading 1 style in the
document."

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top