adding a page number in a cell
You place the code in the visual basic part of the excel file. If you go to
the "Developer" tab in the ribbon, there should be an option for "Visual
Basic" (it is the left most button I think on the default ribbon for Excel
2007). Once in there, you want to put the code in the "ThisWorkbook"
section....
I hope that makes a bit of sense.
Ben
"Babs" wrote:
I have been trying to figure out, how to increase a number in a cell each
time you print it, for sometime! Now for the stupid question...Where do i
place this code?
Thanks in advance!
Barbara
"Ben Langhammer" wrote:
figured it out... Had to modify part of what you said above, but it seems to
work.
Dim ws As Worksheet
Dim lngPageNumber As Long
Dim hPgBrks As Long
lngPageNumber = 0
For Each ws In ActiveWindow.SelectedSheets
hPgBrks = 0
If ws.HPageBreaks.Count = 0 Then
hPgBrks = 1
Else
hPgBrks = ws.HPageBreaks.Count + 1
End If
lngPageNumber = lngPageNumber + hPgBrks
ws.Range("Z1").Value = lngPageNumber
Next ws
Thanks for the great posts that helped me figure it out "on my own".
Ben
"Ben Langhammer" wrote:
How could you get it to work if some worksheets are larger than 1 printed
page in size?
"Bill Renaud" wrote:
Anyway, maybe you mean to use something like the following. It puts a page
number in cell I7 on each of the selected worksheets starting at (page) 1.
This assumes that each worksheet is only 1 printed page in size.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim ws As Worksheet
Dim lngPageNumber As Long
lngPageNumber = 0
For Each ws In ActiveWindow.SelectedSheets
lngPageNumber = lngPageNumber + 1
ws.Range("I7").Value = lngPageNumber
Next ws
End Sub
--
Regards,
Bill Renaud
|