Header and footer macro

N

Natalie

I need to create a macros that will insert different headers and footers into
a particular document. So far, I've created a successful macro that copies
the header and footer on page 1 of a template and pastes it into page 1 of an
existing document. Now for the dilemma, page 2 needs to have a different
header and footer. I already have the page 1 header and footer set to be
different from all other pages. The problem is, how do I get a macro to
access the page 2 header on my template and copy that into page 2 of the
existing document. I tried to record a macro doing this, but it doesn't
insert anything into my existing document. I think it needs a page break
inserted or something. Is there a way to insert a page break at the end of a
page, regardless of what text is on it? Is this possible? Please help!!!
 
N

Natalie

Is there a way to have a macro go to the end of text on page 1 and insert a
page break?
 
A

alborg

Hi Natalie:

For your second question, try-

Dim xEnd As Integer, i As Integer
ActiveDocument.Select
i = 1
For i = 1 To 45
Selection.TypeParagraph
Next i
Selection.InsertBreak Type:=wdPageBreak

Cheers,
Al
 
A

alborg

Hi Natalie:

Try this-

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Footers(wdHeaderFooterFirstPage).Range.InsertBefore
"Written by Kate Edson"
End With
Dim xEnd As Integer, i As Integer
ActiveDocument.Select
i = 1
For i = 1 To 45
Selection.TypeParagraph
Next i
Selection.InsertBreak Type:=wdPageBreak
With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter "This is
the second page"
End With

Cheers,
Al
 
R

Russ

Inline reply
I need to create a macros that will insert different headers and footers into
a particular document. So far, I've created a successful macro that copies
the header and footer on page 1 of a template and pastes it into page 1 of an
existing document.

The concept of templates is that you set it up to have whatever you want
repeated in your documents and either add it as a global template (which
would affect all documents) or attach it to a newly added document (which
limits the template's scope to that document).

No copy and paste needed.

Create the template with the header or footers you require and then have it
attached to the document when you add it.
Now for the dilemma, page 2 needs to have a different
header and footer. I already have the page 1 header and footer set to be
different from all other pages. The problem is, how do I get a macro to
access the page 2 header on my template and copy that into page 2 of the
existing document. I tried to record a macro doing this, but it doesn't
insert anything into my existing document.
I think it needs a page break
inserted or something. Is there a way to insert a page break at the end of a
page, regardless of what text is on it? Is this possible? Please help!!!

Having two consecutive page breaks in a row will generate a blank page. Is
that what you wanted?
 

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