I have an Excel file with repeating rows. Inside this repeating rows, I wanted to place "Page 1 of 2" and "Page 2 of 2", etc. into each page. I found this VBA code which worked fine when printing the file, but doesn't work when saving the file as PDF.
Sub PrintWithPgNumInTitleRow()
Dim NumPages As Long, pg As Long
NumPages = ExecuteExcel4Macro("Get.document(50)")
For pg = 1 To NumPages
With ActiveSheet
.Range("O10").Value = "Page " & pg & " of " & NumPages
.PrintOut from:=pg, To:=pg
End With
Next pg
End Sub
When I changed my default printer to pdf writer, it requires me to input two file names (for two pages), but I wanted to have these two pages in one file only.