Page number reference in a cell

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!
 
B

Ben Langhammer

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
 

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