How do I print a footer on the last page only of an excel doc?

C

CLDelafield

How do I print a footer on the last page only of an excel doc? Is this
possible?
 
R

Ron de Bruin

Hi

Only with code

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
 
J

Jim Cone

CLD,

Print all pages except the last page.
Add the footer information.
Print the last page.
Close the workbook without saving.

Jim Cone
San Francisco, USA


How do I print a footer on the last page only of an excel doc?
Is this possible?
 
D

DNA

If, when you say pages, you're referring to sheets or worksheets, then the
answer is simple.

If you place a header or a footer on Sheet1, it does not automatically go
to the other sheets; therefore, put your footer on the last worksheet and
print all pages.

HTH and I'm not missing something.
 
J

Jim May

Even at xl2003 version, are we still bound to "Excel4Macro" code to acheive
TotPages? hummm..
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
TIA,
 
T

TC

I have some experience with VB code but not much. Could someone please
explain what parts of this code I have to edit and enter specific information
for my worksheet to get this code to run.
Thanks
Tim
 
R

Ron de Bruin

Hi Tc

I not see code but I have this on my site
http://www.rondebruin.nl/print.htm#Header

You can do 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
 
T

TC

Ron,
I was using your code from below.
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
Is there any way for the code to recognize the footer information that I
have typed in for the worksheet. Instead of having to type it in the line
..rightfooter = "Your Header info"
Also how do you change the code so that it prints on the first page and not
on any of the remaining pages?

Thanks
Tim
 
R

Ron de Bruin

I was using your code from below.

The code I posted is not the site code but only print the footer on the last page
Is there any way for the code to recognize the footer information that I
have typed in for the worksheet. Instead of having to type it in the line
.rightfooter = "Your Header info"

Add your header info in a cell outside you print area
You can use this value in the macro then.
Also how do you change the code so that it prints on the first page and not
on any of the remaining pages?

Sub Test2()
Dim TotPages As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With ActiveSheet.PageSetup
.RightFooter = Range("Z1").Value
ActiveSheet.PrintOut From:=1, To:=TotPages - 1, preview:=True
.RightFooter = ""
ActiveSheet.PrintOut From:=2, To:=TotPages, preview:=True
End With
End Sub
 
T

TC

Ron,
Thank you very much for all of your help. I think I have envery thing
working the way I want.
Thanks
Tim
 
T

TC

Ron,
When I run the code in the VB editor it does everything that I want it to.
However when I go to print preview in Excel the footer information doesn't
appear. Or when I go to view header/ footer it is not thier either. In my
earlier attempts to get everything working it did appear in the view header/
footer but I have not been able to repete this. I know there is an auto open
feature for macros in Excel but I have not been able to figure it out.

Sub Test()
Dim TotPages As Long
TotPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
With Worksheets("Sheet1").PageSetup
..CenterFooter = Worksheets("Sheet2").Range("A1:A2").Value
ActiveSheet.PrintOut From:=1, To:=TotPages - 1, preview:=True
..CenterFooter = ""
ActiveSheet.PrintOut From:=2, To:=TotPages, preview:=True
End With
End Sub

Thank you for all of your help.
Tim
 
Top