Style Count in Word 2003

  • Thread starter Thread starter Amish
  • Start date Start date
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.
 
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
 
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.
 
Back
Top