Add Page Header and Footer

M

Mei Qin

Hello,

Can I add page header and footer to a open document using
vba? How can I do that?

Thanks for any help!

Mei
 
D

Doug Robbins

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "This
is the text for the primary header in Section 1 of the ActiveDocument"

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

Mei Qin

It works fine for just one line. When I add the
pagenumber using .pagenumber.add, the text dispeared. How
can I add the pagenumber under the first line and center
the text and the pagenumber?

Thanks for the help!

Mei
-----Original Message-----
ActiveDocument.Sections(1).Headers
(wdHeaderFooterPrimary).Range.Text = "This
 
D

Doug Robbins

Making use of the centre aligned tab that is already in the Header, use

Dim myrange As Range
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertBefore
vbTab & "this is the text" & vbCr & vbTab
Set myrange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.Collapse wdCollapseEnd
ActiveDocument.Fields.Add myrange, wdFieldPage


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent 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