rog1111
06-07-2010, 04:17 AM
Hi all. I am trying to print a workbook with several worksheets, some of which have a variable number of page breaks. I need to correctly number each page in the print, and this must happen dynamically via VBA since page sizes vary.
The number of page breaks per sheet is easy enough to figure out using code, eg
s6 = Sheets("commitmentsO").HPageBreaks.Count
So I can get the starting page number for each sheet by adding up the HPageBreaks for each prior sheet, eg
COpagestart = Notespageend + 1
COpageend = COpagestart + s6
Now I have code to add the page number in the footer, eg
With Sheets("commitmentsO").PageSetup
.Orientation = xlLandscape
.Order = xlOverThenDown
.FirstPageNumber = COpagestart
.CenterFooter = "Page " & COpagestart
End With
Then I finally print out all the visible sheets in the workbook:
ThisWorkbook.PrintOut
(I have edited the code just to show one sheet)
The problem is that this sheet ("commitmentsO") has 2 page breaks (ie 3 pages), but each page prints out with the same page number, in this case, 6.
My question is, how do I get correct page numbers on each of these 3 pages (6,7 & 8) ?
Ideas anyone?
Thanks
rog1111
The number of page breaks per sheet is easy enough to figure out using code, eg
s6 = Sheets("commitmentsO").HPageBreaks.Count
So I can get the starting page number for each sheet by adding up the HPageBreaks for each prior sheet, eg
COpagestart = Notespageend + 1
COpageend = COpagestart + s6
Now I have code to add the page number in the footer, eg
With Sheets("commitmentsO").PageSetup
.Orientation = xlLandscape
.Order = xlOverThenDown
.FirstPageNumber = COpagestart
.CenterFooter = "Page " & COpagestart
End With
Then I finally print out all the visible sheets in the workbook:
ThisWorkbook.PrintOut
(I have edited the code just to show one sheet)
The problem is that this sheet ("commitmentsO") has 2 page breaks (ie 3 pages), but each page prints out with the same page number, in this case, 6.
My question is, how do I get correct page numbers on each of these 3 pages (6,7 & 8) ?
Ideas anyone?
Thanks
rog1111