Style Instances Count?

M

ML

Is there a way to reference the number of instances of a Style that is being
used in a document similar to the way that you get this when right clicking
on the style name in the Stayles and Formatting window?

I want to get the number of paragraphs that are formatted in a specific
style.

I'm currently doing the following but it is slow:

For i = 1 To ActiveDocument.Paragraphs.Count
If ActiveDocument.Paragraphs(i).Style = ActiveDocument.Styles("My
Styles") Then
x = x + 1
End If
Next i
 
H

Helmut Weber

Hi,

this one _might_ work for a rather ordinary word document.
There are lots of complications, therefore I put in something
to prevent endless loops. And don't forget to reset search
options.

Sub test9999()
Dim l As Long
resetsearch
With ActiveDocument.Range.Find
.Style = "00-tt-dc"
While .Execute
l = l + 1
If l > ActiveDocument.Range.Paragraphs.Count Then
Stop
End If
Wend
End With
MsgBox l
resetsearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub


Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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