Ask Word whether first page header of a section is on an odd page?

A

andreas

Hello,

I got a long word document with several sections, each section with
different first page header and different headers for odd and even
pages.

Can Word VBA tell me whether the first page header of a given section
is on an even (or odd) page, so that a boolean value is returned (True
or False)?

Help is appreciated. Thank you in advance.

Regards,

Andreas
 
C

Cindy M.

Hi Andreas,
I got a long word document with several sections, each section with
different first page header and different headers for odd and even
pages.

Can Word VBA tell me whether the first page header of a given section
is on an even (or odd) page, so that a boolean value is returned (True
or False)?
Word can't tell you that directly. But you can calculate it. Example:
Sub CalculateEvenOddPageSectionStart()
Dim rng As Word.Range
Dim sec As Word.Section

'Loop through all the sections in the current doc
For Each sec In ActiveDocument.Sections
Set rng = sec.Range
'Get the start of the section
rng.Collapse wdCollapseStart
'MOD gets the remainder after dividing with 2
'If it's 0, then it's an even page number
If rng.Information(wdActiveEndAdjustedPageNumber) Mod 2 = 0 Then
MsgBox "Section " & sec.Index & " starts on an even page"
Else
MsgBox "Section " & sec.Index & " starts on an odd page"
End If
Next
End Sub


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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