Headers, first pages, page numbers

D

Dave Stone

In an attempt to prevent this slipping too far down the
list, I'm re-posting a distilled version of this problem:

I am generating a document which has distinct first page
header and footer and all pages are numbered (in the
footer).

With the following code:

With ActiveDocument.Sections(1)
SubjCateg = "CLASSICS"
DiffCateg = "DIFFERENT"
DateRange = "<date1> - <date2>"
.Headers(wdHeaderFooterFirstPage).Range.Text =
DiffCateg
.Headers(wdHeaderFooterPrimary).Range.Text =
SubjCateg
.Footers(wdHeaderFooterFirstPage).Range.Text
= "SPLAT" & FootText
.Footers(wdHeaderFooterPrimary).Range.Text =
FootText
.Footers
(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSecti
on = True
.Footers
(wdHeaderFooterPrimary).PageNumbers.StartingNumber = 5
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=True
End With
ActiveDocument.Sections
(1).PageSetup.DifferentFirstPageHeaderFooter = True

the first page headers and footers are indeed distinct,
but the page number does not appear (only) on the first
page.

I have tried also putting the appropriate equivalent page
number statements for Footers(wdHeaderFooterFirstPage),
but this gives an error: subscript out of range.

Any help gratefully received.

Dave
 
D

Doug Robbins - Word MVP

Hi Dave,

It's a lot simpler to set up a template that has the headers/footers in it
the way you want, with {DOCVARIABLE} fields in the appropriate places and
just have your code create a new document from the template and assign
values to the variables and then update the fields.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Dave Stone

I'm not sure how this would work in my particular context,
Doug. I'm inserting data from an Access recordset into a
template at specified bookmarks, then appending the result
for each record to an 'output' document. Once all records
have been processed, I try to set up the headers/footers
on the output document (with page 1 distinct) before
printing/saving it.

Your method raises questions in my mind (forgive my Word
naivety):
1. My template is very short (5 lines) - can I still
define headers/footers for page 2 onwards of the template?

2. I had been copying/pasting my (header-less/footer-less)
template via the Clipboard into the output document and
that worked fine. But this doesn't copy headers or
footers. Do I have to loop round all the template's
storyranges copying each one, or is there an easier way?

Dave
 
D

Doug Robbins - Word MVP

Hi Dave,

Reur Question 1, the answer is "Yes". With your template, set up the
headers and footers that you want to appear on the second and subsequent
pages and then from the Headers and Footers toolbar click on the Page Setup
button (it looks like and open book" and check the Different First Page box
and then click on OK and you will now see a first page header and footer
area in which you can set up the information that you want to appear in
those headers. The headers that you first set up will reappear when/if a
second page is added to a document that is created from the template.

Reur Question 2, that is NOT the right way to use the template. You should
be doing the following

Dim mydoc as Document

Set mydoc = Documents.Add("Drive:\Folder\YourTemplate.dot")

then

With mydoc
.Variables("varname").Value = [Access Data]

.Fields.Update
.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Fields.Update
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update
.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Fields.Update
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Fields.Update
End With

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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