Get total number of pages to be printer.


New Member
Aug 6, 2010
Hi everyone. I need a method or function that can count the TOTAL number of pages to that will be printed. I don't need anything with HPageBreaks or Get.document(50, ""sheet name"")") for these don't seem to work on my worksheet.

All they seem to do is give me a number lower then the number of pages that will be printed and they are dependent on where the active cell is.

Here is my code that does not work.

 Agreement_Page_Count = ExecuteExcel4Macro("Get.document(50,""Signature Page"")")

Function HowManyPagesBreaks(sSheet As Worksheet)
Dim iHpBreaks As Integer, iVBreaks As Integer
Dim iTotPages As Integer
    With sSheet
        .UsedRange.EntireRow.Hidden = True
        .UsedRange.EntireColumn.Hidden = True
        .Range(.PageSetup.PrintArea).EntireRow.Hidden = False
        .Range(.PageSetup.PrintArea).EntireColumn.Hidden = False
    End With
    iHpBreaks = sSheet.HPageBreaks.Count + 1
    iVBreaks = sSheet.VPageBreaks.Count + 1
    HowManyPagesBreaks = iHpBreaks * iVBreaks
    With sSheet
        .UsedRange.EntireRow.Hidden = False
        .UsedRange.EntireColumn.Hidden = False
    End With
End Function
Both codes return 2 when there are 3 pages that can be printed. Unless I pause the code select the cell at the bottom of my sheet (it ignores it if I use use a macro to select the bottom cell) and then continue my code.

I've tried it with and without the entirerow.hidden.

Is there a way of bypassing everything and using a marco to open up page preview and getting the total number of page to be printed?

If it helps I'm using excel 2010


New Member
Aug 6, 2010
I found a solution that is slow as molasses. Could anyone help me find a way to speed up this solution. I have ~17 pages to go through line by line on one sheet and on the other I have ~3.

Function HowManyPagesBreaks(sSheet As Worksheet)
Dim iRowEnd As Integer
Dim iRow As Integer
Dim Page_Count As Integer
iRowEnd = sSheet.Range("A2000").End(xlUp).Row
Page_Count = 1
For iRow = 1 To iRowEnd
    If sSheet.Rows(iRow).PageBreak <> -4142 Then
        Page_Count = Page_Count + 1
    End If
HowManyPagesBreaks = Page_Count
End Function

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...