Page number reference in a cell

  • Thread starter Thread starter Ben Langhammer
  • Start date Start date
B

Ben Langhammer

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!
 
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
 
Back
Top