Page numbers

G

Guest

I am trying to put sequential page numbers on each worksheet for the
worksheet and also put sequential page number for the entire workbook. So
the print out for worksheet 1 has Page 1 of 1 and also Page 1 of 45 on the
same page. Can anyone tell me if this is possible and how I do it?
 
G

Guest

I think this will do what you are asking. Put the code in the ThisWorkBook
module in the VBA editor.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim i As Long
Dim PgCnt As Long
Dim PgCntTotal As Long
Dim lngTemp As Long

Application.ScreenUpdating = False

lngTemp = ActiveSheet.Index
For i = 1 To Sheets.Count
Sheets(i).Activate
If i < lngTemp Then _
PgCnt = PgCnt + ExecuteExcel4Macro("Get.Document(50)")
PgCntTotal = PgCntTotal + ExecuteExcel4Macro("Get.Document(50)")
Next i

Sheets(lngTemp).Activate
With ActiveSheet.PageSetup
.RightFooter = "&P Of &N" & Chr(10) & "&P+" & PgCnt & " Of " & PgCntTotal
End With

Application.ScreenUpdating = True

End Sub
 
G

Guest

After thinking about it, that won't work properly if you select multiple
sheets to be printed or want to print the entire workbook at once as the
macro only modifies the footer on the activesheet (but printing out one sheet
at a time should work okay). I think it would be a little tricky to
accomodate all scenarios (ie printing one sheet, printing multiple sheets,
printing entire workbook).
 

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