ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   page numbering in an Excel cell (https://www.excelbanter.com/excel-discussion-misc-queries/451361-re-page-numbering-excel-cell.html)

[email protected]

page numbering in an Excel cell
 
On Tuesday, July 27, 1999 at 3:00:00 AM UTC-4, Myrna Larson wrote:
On Mon, 26 Jul 1999 22:22:55 -0400, "David McRitchie"
wrote:

you can thank Dana for the concept, which is really
remarkable


I agree. Those old XLM macro functions are really far back in my mind. But they
can get you out of all sorts of jams like this problem of how many pages there
are in the printed document. I'm really surprised there's no VBA command for
this.

Anyway, if you want the page number on all pages, it needs one more change to
get rid of the part that excludes page 1:

Sub Demo()
Dim TotalPages As Long
Dim pg As Long

TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet
.Range("D5").Value = pg & " of " & TotalPages '<<< CHANGE HERE
.PrintOut From:=pg, To:=pg
End With
Next pg
End Sub


I like this macro but how do you start from the first page and I ran it and it would change the current page number it would make it equal to the total pages.
Here is the one I am using.

Sub Pages()
Dim TotalPages As Long
Dim pg As Long


TotalPages = ExecuteExcel4Macro("Get.Document(50)")
For pg = 1 To TotalPages
With ActiveSheet

.Range("F1").Value = pg & " _ " & TotalPages

End With
Next pg
End Sub


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

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