Number of even-page section breaks in a document

A

andreas

Dear Experts:

I would like to know whether it is possible to retrieve the number of
even-page section breaks in the current document and display the
result in a MsgBox?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
 
J

Jay Freedman

Dear Experts:

I would like to know whether it is possible to retrieve the number of
even-page section breaks in the current document and display the
result in a MsgBox?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub CountEvenPageSectionBreaks()
Dim oSec As Section
Dim EvenCount As Long

For Each oSec In ActiveDocument.Sections
If oSec.PageSetup.SectionStart = wdSectionEvenPage Then
EvenCount = EvenCount + 1
End If
Next

MsgBox EvenCount & " Even Page section break(s)"
End Sub
 
G

Greg Maxey

Sub CountEvenPageSectionBreaks()
    Dim oSec As Section
    Dim EvenCount As Long

    For Each oSec In ActiveDocument.Sections
        If oSec.PageSetup.SectionStart = wdSectionEvenPage Then
            EvenCount = EvenCount + 1
        End If
    Next

    MsgBox EvenCount & " Even Page section break(s)"
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroupso all may benefit.

Hi Jay,

I was toying with something similar when your post appeared. If the
first section starts as a even page section I wander if it should be
counted as break?

Sub CountEvenPageSectionBreaks()
Dim i As Long
Dim Cnt As Long
'start with section 2
For i = 2 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).PageSetup.SectionStart =
wdSectionEvenPage Then
Cnt = Cnt + 1
End If
Next
MsgBox Cnt
End Sub
 
J

Jay Freedman

Hi Greg

Hi Jay,

I was toying with something similar when your post appeared. If the
first section starts as a even page section I wander if it should be
counted as break?

Sub CountEvenPageSectionBreaks()
Dim i As Long
Dim Cnt As Long
'start with section 2
For i = 2 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).PageSetup.SectionStart =
wdSectionEvenPage Then
Cnt = Cnt + 1
End If
Next
MsgBox Cnt
End Sub

You're correct.

I don't think I've ever set the first section to start on an even page
by setting its .SectionStart, only by changing the page number (which
is what the Envelope > Add to Document does when it adds page 0). But
if someone does that, it shouldn't count as an even section break.
 
A

andreas

Hi Jay,

I was toying with something similar when your post appeared.  If the
first section starts as a even page section I wander if it should be
counted as break?

Sub CountEvenPageSectionBreaks()
Dim i As Long
Dim Cnt As Long
'start with section 2
For i = 2 To ActiveDocument.Sections.Count
  If ActiveDocument.Sections(i).PageSetup.SectionStart =
wdSectionEvenPage Then
     Cnt = Cnt + 1
  End If
Next
MsgBox Cnt
End Sub- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hi Greg,

thank you very much for your looking into this matter a little deeper.
It works just fine.

Regards, Andreas
 
A

andreas

Sub CountEvenPageSectionBreaks()
    Dim oSec As Section
    Dim EvenCount As Long

    For Each oSec In ActiveDocument.Sections
        If oSec.PageSetup.SectionStart = wdSectionEvenPage Then
            EvenCount = EvenCount + 1
        End If
    Next

    MsgBox EvenCount & " Even Page section break(s)"
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroupso all may benefit.

Dear Jay,

thank you very much for your terrific help. It works as desired.
Regards, Andreas
 
G

Greg Maxey

You are welcome. Like Jay, I haven't ever intentionally set the first
section to start as an even page either. I just wasn't sure if you were
really looking for the number of sections that starts with an even page or
the physical breaks.

Hi Jay,

I was toying with something similar when your post appeared. If the
first section starts as a even page section I wander if it should be
counted as break?

Sub CountEvenPageSectionBreaks()
Dim i As Long
Dim Cnt As Long
'start with section 2
For i = 2 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).PageSetup.SectionStart =
wdSectionEvenPage Then
Cnt = Cnt + 1
End If
Next
MsgBox Cnt
End Sub- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hi Greg,

thank you very much for your looking into this matter a little deeper.
It works just fine.

Regards, Andreas
 

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