From: andreas on
Dear Experts:

I would like to loop thru all paragraphs and check how many paragraphs
have been formatted with a specific user-defined paragraph style (say
user-defined-style-1). A Msg Box is to show me the numbers of
paragraphs formatted with this style.

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
From: Graham Mayor on
Something like

Dim oSection As Section
Dim oPara As Paragraph
Dim i As Long
i = 0
For Each oSection In ActiveDocument.Sections
For Each oPara In oSection.Range.Paragraphs
If oPara.Style = "user-defined-style-1" Then i = i + 1
Next oPara
Next oSection
MsgBox i


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"andreas" <andreas.hermle(a)gmx.de> wrote in message
news:5f6a58fc-fea2-40a8-8fad-9e730a8cb749(a)r34g2000yqj.googlegroups.com...
> Dear Experts:
>
> I would like to loop thru all paragraphs and check how many paragraphs
> have been formatted with a specific user-defined paragraph style (say
> ). A Msg Box is to show me the numbers of
> paragraphs formatted with this style.
>
> Help is much appreciated. Thank you very much in advance. Regards,
> Andreas


From: Fumei2 via OfficeKB.com on
Do you actually need the Section?

Sub CountEm()
Dim oPara As Paragraph
Dim j As Long

For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.Style = "Yadda" Then
j = j + 1
End If
Next
MsgBox "There are " & j & " paragraphs using the Yadda style."
End Sub

works for me. Not sure why you explicitly set i = 0, as it should be 0
simply by declaring it. Although I certainly am in favour of explicitness.

Gerry

Graham Mayor wrote:
>Something like
>
>Dim oSection As Section
>Dim oPara As Paragraph
>Dim i As Long
>i = 0
>For Each oSection In ActiveDocument.Sections
> For Each oPara In oSection.Range.Paragraphs
> If oPara.Style = "user-defined-style-1" Then i = i + 1
> Next oPara
>Next oSection
>MsgBox i
>
>> Dear Experts:
>>
>[quoted text clipped - 5 lines]
>> Help is much appreciated. Thank you very much in advance. Regards,
>> Andreas

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1

From: andreas on
On 3 Mai, 16:27, "Graham Mayor" <gma...(a)REMOVETHISmvps.org> wrote:
> Something like
>
> Dim oSection As Section
> Dim oPara As Paragraph
> Dim i As Long
> i = 0
> For Each oSection In ActiveDocument.Sections
>     For Each oPara In oSection.Range.Paragraphs
>         If oPara.Style = "user-defined-style-1" Then i = i + 1
>     Next oPara
> Next oSection
> MsgBox i
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor -  Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> "andreas" <andreas.her...(a)gmx.de> wrote in message
>
> news:5f6a58fc-fea2-40a8-8fad-9e730a8cb749(a)r34g2000yqj.googlegroups.com...
>
>
>
> > Dear Experts:
>
> > I would like to loop thru all paragraphs and check how many paragraphs
> > have been formatted with a specific user-defined paragraph style (say
> > ). A Msg Box is to show me the numbers of
> > paragraphs formatted with this style.
>
> > Help is much appreciated. Thank you very much in advance. Regards,
> > Andreas- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Dear Graham,

thank you very much for your professional help. It works just fine
although I have to admit, I am not quite sure why you are using the
section-object.

Regards, Andreas
From: andreas on
On 3 Mai, 20:04, "Fumei2 via OfficeKB.com" <u53619(a)uwe> wrote:
> Do you actually need the Section?
>
> Sub CountEm()
> Dim oPara As Paragraph
> Dim j As Long
>
> For Each oPara In ActiveDocument.Paragraphs
>    If oPara.Range.Style = "Yadda" Then
>       j = j + 1
>    End If
> Next
> MsgBox "There are " & j & " paragraphs using the Yadda style."
> End Sub
>
> works for me.  Not sure why you explicitly set i = 0, as it should be 0
> simply by declaring it.  Although I certainly am in favour of explicitness.
>
> Gerry
>
>
>
>
>
> Graham Mayor wrote:
> >Something like
>
> >Dim oSection As Section
> >Dim oPara As Paragraph
> >Dim i As Long
> >i = 0
> >For Each oSection In ActiveDocument.Sections
> >    For Each oPara In oSection.Range.Paragraphs
> >        If oPara.Style = "user-defined-style-1" Then i = i + 1
> >    Next oPara
> >Next oSection
> >MsgBox i
>
> >> Dear Experts:
>
> >[quoted text clipped - 5 lines]
> >> Help is much appreciated. Thank you very much in advance. Regards,
> >> Andreas
>
> --
> Gerry
>
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Dear Gerry,

it is working just fine. Thank you very much for your professional
help. Regards, Andreas