#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Page numbers

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?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Page numbers

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

"Puzzled" wrote:

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?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Page numbers

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).

"JMB" wrote:

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

"Puzzled" wrote:

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?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Page numbers

Forgot to thank Mr. Walkenbach for his tip on getting the number of printed
pages

http://www.j-walk.com/ss/excel/tips/tip65.htm

"JMB" wrote:

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

"Puzzled" wrote:

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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resetting page numbers Vince Excel Discussion (Misc queries) 6 September 12th 06 04:36 PM
Big background page numbers/ Can't change format of a range Micky01 New Users to Excel 2 April 23rd 06 09:28 PM
Why are 1/2 my numbers imported as text and the rest as numbers? KBear Excel Discussion (Misc queries) 2 April 21st 06 01:40 PM
Page Numbers W/i Spreadsheet ChemistB Excel Discussion (Misc queries) 6 January 9th 06 08:50 PM
IN EXCEL, TURN OFF THE BIG GRAY NUMBERS IN THE PAGE BREAK PREVIEW JAGMWF Excel Discussion (Misc queries) 4 January 5th 06 01:40 PM


All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"