Headers, footers, and page numbers

D

Dave Stone

I still cannot get my output document looking as I want
it, viz. section 1 header with different first page;
section 1 footer common to all pages; page numbers in the
footer, assigned starting number.

There have been various problems including all headers
coming out the same, missing page numbers on the first
page, and wrong page numbers. Using the debugger, it has
been possible to see that the sequence of formatting
directives is critical in determining the outcome, but
it's not clear what the order should be!

The only things that seem certain are that the directive
to make the first page header/footer distinct:

ActiveDocument.Sections _
(1).PageSetup.DifferentFirstPageHeaderFooter = True

has to come after all the formatting directives for the
primary and first page headers and footers, otherwise the
primary specs override the first page ones.

I have the directive to add page nos. in the primary
footer only because I get a subscript error if I put one
in the first page footer, but this unfortunately
suppresses the number on the first page.

Any help, or pointers to a good reference on this subject,
gratefully received.

Dave
 
C

Cindy Meister -WordMVP-

Hi Dave,
I still cannot get my output document looking as I want
it, viz. section 1 header with different first page;
section 1 footer common to all pages; page numbers in the
footer, assigned starting number.
Unfortunately, I can't recall having seen any of the code
you've been struggling with. So it's really hard to know
where to start. Basically, it shouldn't matter where you put
the DifferentFirstPage thing. Most important is to not try
to do this with any recorded macro code. And NEVER use the
InsertPagenumber stuff. Insert FIELDS, instead.

Does this work correctly?

ActiveDocument.Sections _
(1).PageSetup.DifferentFirstPageHeaderFooter = True
With ActiveDocument.Sections(1)
.Headers(wdHeaderFooterFirstPage).Range.Text = "ONE"
.Headers(wdHeaderFooterPrimary).Range.Text = "P:H"
.Footers(wdHeaderFooterFirstPage).Range.Text = "F"
.Footers(wdHeaderFooterPrimary).Range.Text = "F"
End With

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

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

Dave Stone

Thanks for your reply, Cindy. No, I hadn't posted the code
because of the complexity, but you're correct in your
approach - we need to start simple and build up the
complexity until things start to fall apart.

Fortunately :)-)) this doesn't take long...

Your example works OK as given, BUT where I am really
struggling is getting page numbers the way I want them.
They should appear on all pages including the first, in
the footer (and I'll want to assign the starting number,
but let's learn to walk first, eh?).

If I add, before 'End With', the following:

.Footers _
(wdHeaderFooterPrimary).PageNumbers _
.RestartNumberingAtSection = True
.Footers _
(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=True

then the 1st page header and footer come out the same as
the primary.

If I then move the statement:

ActiveDocument.Sections _
(1).PageSetup.DifferentFirstPageHeaderFooter = True

to just AFTER 'End With', the first page header and footer
go back to being distinct, but the page number disappears
off the first page only.

I've tried putting the page-number directives with
FirstPage instead of Primary, but this gives error 9:
subscript out of range.

I've yet to devise a method of getting distinct first-page
headers/footers AND numbers on every page!

Any ideas gratefully accepted...

Dave
 
C

Cindy Meister -WordMVP-

Hi Dave,

I'd say where you're stumbling is in trying to use the
equivalent of Insert/Page number. This functionality (a
PAGE field in a frame) simply doesn't work reliably in
complicated documents (multiple sections with different
first pages).

Instead, insert a PAGE field directly into the footer
range. In order to align it to the right, you want to make
sure you have a TAB stop at that location, and put a TAB
character in before inserting the field. Roughly:

Set rng = .Footers(wdHeaderFooterPrimary).Range
rng.Text = vbTab
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, Page, "", False
BUT where I am really
struggling is getting page numbers the way I want them.
They should appear on all pages including the first, in
the footer (and I'll want to assign the starting number,
but let's learn to walk first, eh?).

If I add, before 'End With', the following:

.Footers _
(wdHeaderFooterPrimary).PageNumbers _
.RestartNumberingAtSection = True
.Footers _
(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=True

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jan 24 2003)
http://www.mvps.org/word

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