How to figure out pages for header/footer?

E

Edgar E. Cayce

I need to figure out, for each type of header/footer (Primary, First
Page, Even Pages), on how many pages does this header appear?

What I am doing right now is using
Range.Information(wdActiveEndPageNumber) to figure out the last page
upon which the header appears, and doing some calculations based on
what other headers exist and their page numbers - but I am wondering
if there is a simpler way to do it?

Ed
 
J

Jezebel

If you have to allow for multiple sections, each with its own header/footer
settings, this could get quite tricky. Most reliable would be to iterate the
pages of the document and work out what sort of footer appears on each, and
do the count that way.
 
E

Edgar E. Cayce

How do you figure out headers by iterating Pages? I don't see them
(or the Page object) having many useful properties for this.
 
J

Jezebel

It depends rather on what you need to end with. If you want a count of the
number of instances of each footer type, you go to each page in turn, find
its last paragraph (in case there are continuous section breaks within the
page), then check what section you're in:

if it's not the same section as you were previously in and this section uses
different first page footers, then this page has a first-page footer;

else if the page number is even and this section uses even/odd footers, then
this page has an even-page footer

else this page has a primary page footer.
 
E

Edgar E. Cayce

If anyone is interested...

After a week of finagling with Word VBA, I managed to come up with a
workable solution for figuring out on which pages the various types of
headers and footers appear, and how many times - this is so I can
count the chars in them.

For instance, a wdPrimaryHeaderStory may appear on many pages in the
doc, but only exists once in the Word representation - my code figures
out how many times it shows up so the count can be multiplied by that.

Basically, I iterate through the Sections collection, using
Information(wdActiveEndAdjustedPageNumber) to figure out what pages
the sections are on, and then do some tricks to account for continuous
section breaks and "Even Page/Odd Page? breaks. I store that in an
array of structures containing for this info later use.

I then go through headers and footers for each section and use the
data in my array to figure out how many times those headers & footers
appear.

If anone wants to see the code, post here or email me. It was a real
bitch!

Ed
 

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