ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Page number reference in a cell (https://www.excelbanter.com/excel-programming/414182-page-number-reference-cell.html)

Ben Langhammer[_2_]

Page number reference in a cell
 
Is there a way to reference the page number of a page in the middle of a
document and input it into a cell. The problem is that as information is
added or deleted the page will move so I am trying to write something to
reference what that page number will be when it is printed.

Thanks!

Ben Langhammer[_2_]

Page number reference in a cell
 
Found a way

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


All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com