Get total number of pages to be printer.

Tolure

New Member
Joined
Aug 6, 2010
Messages
11
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.

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

and

Code:
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
    'sSheet.Range("A2000").End(xlUp).Select
    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
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Tolure

New Member
Joined
Aug 6, 2010
Messages
11
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.

Code:
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
Next
HowManyPagesBreaks = Page_Count
End Function
 

Watch MrExcel Video

Forum statistics

Threads
1,122,529
Messages
5,596,695
Members
414,088
Latest member
rodriboraun

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top