insert page footer on every page

S

sals

This code from vb help is suppose to add a page number to the primary
footer in the first section and in any subsequent sections. The page
number doesn't appear on the first page.

With ActiveDocument.Sections(1)
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberLeft, _
FirstPage:=False
End With

I'm running it and getting the error you can specify only one line,
footnote, endnote, comment, or field at a time.

I am trying to insert the page number in the footer on every page of
the doc.
but it is not even inserting it onto one page.

please help.
 
D

DA

Try the following:

Sub AddPageNo()
Dim mySCTN As Section

For Each mySCTN In ActiveDocument.Sections
With ActiveDocument.Sections(mySCTN.Index).Footers _
(wdHeaderFooterPrimary)
.PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight
End With
Next mySCTN

End Sub
 
S

sals

Thanks Dennis,

Your code works, but I notice the problem has to do more with the
breaks I have in the pages. If the page has a section break, no page
number is displayed. If the page has a page break, the page number is
displayed.

Any ideas?

Sally
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < sals > écrivait :
In this message, < sals > wrote:

|| Thanks Dennis,
||
|| Your code works, but I notice the problem has to do more with the
|| breaks I have in the pages. If the page has a section break, no page
|| number is displayed. If the page has a page break, the page number is
|| displayed.
||
|| Any ideas?
||

<quote>
This code from vb help is suppose to add a page number to the primary
footer in the first section and in any subsequent sections. The page
number doesn't appear on the first page.
<unquote>

Just in case, is your document set to have "First page different" (File >
Page Setup > Layout tab)?
If so, you have to iterate through those first page headers/footers as well,
or uncheck it if you do not need this type of setting.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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