Reputation: 11
I made a function that counts the number of pages. At least I thought so... It is counting the number of worksheets... If a worksheet has more than one page it does not count it... Does anyone have any idea how to count page of a workbook? I cant use excel page count function because I am using a macro to fill data of footer and header.
Function Showpage()
Application.Volatile
Showpage = ActiveSheet.Index & "/" & Worksheets.Count
End Function
that is the code I use for counting pages...
Upvotes: 1
Views: 2842
Reputation: 9538
May be
Sub Test()
Dim totPages As Integer
totPages = ActiveSheet.PageSetup.Pages.Count
MsgBox "The Number Of Print Pages On The Worksheet Is " & totPages
End Sub
Upvotes: 1
Reputation: 2309
A formula that will find you the number of pages that will be printed can be written using the ExecuteExcel4Macro method.
Showpage = ExecuteExcel4Macro("GET.DOCUMENT(50)")
Note: This formula counts like a printer would count it, and therefore only works for pages with data. If pages are added manually but are blank, they will not be counted.
Upvotes: 0