Printing Headers on only first page and Footers on only last page

G

Guest

I'm controlling the printing of a sheet of various lenght with a macro. How
do I ensure that the Header only prints on the first page, and the Footer
only on the last page. The pages will vary from one to three or four. . .
.. or should I use something else than Headers and Footers?

Thank you
 
G

Guest

JacMar said:
I'm controlling the printing of a sheet of various lenght with a macro. How
do I ensure that the Header only prints on the first page, and the Footer
only on the last page. The pages will vary from one to three or four. . .
. or should I use something else than Headers and Footers?

Thank you

Sorry, I forgot to mention I am using Excel 2002.
 
G

Guest

Thanks, that should work. I also have to find out how to determine the
number of pages that will print, before I start printing, so I can print a
footer only on the last page. If I can't find out, I will get back to this
group. As you can probably tell, I am a "newbie" to VBA. Thanks again.
 
R

Ron de Bruin

Hi JacMar

This give you the pages
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")


Try this

Sub Test()
Dim TotPages As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
.RightFooter = ""
ActiveSheet.PrintOut From:=1, To:=TotPages - 1
.RightFooter = "Your Header info"
ActiveSheet.PrintOut From:=TotPages, To:=TotPages
End With
End Sub
 
R

Ron de Bruin

Printing Headers on only first page and Footers on only last p

I only read the last posting in the thread about only footer on last page

But try this for header on first page and footer on last page

Test TotPages to see if there are enough pages

Sub Test()
Dim TotPages As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
.RightFooter = ""
.RightHeader = "Your Header info"
ActiveSheet.PrintOut From:=1, To:=TotPages - 1

.RightFooter = ""
.RightHeader = ""
ActiveSheet.PrintOut From:=2, To:=TotPages - 1

.RightFooter = "Your footer info"
.RightHeader = ""
ActiveSheet.PrintOut From:=TotPages, To:=TotPages
End With
End Sub
 

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