VB and VBA Users Source Code: Counting the number of printed pages in an Excel worksheet
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Counting the number of printed pages in an Excel worksheet
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, August 01, 2001
Hits:
1054
Category:
Unspecified
Article:
The following routine demonstrates how to count the number of printed pages in a worksheet. Option Explicit 'Purpose : Returns the number of printed pages in a worksheet 'Inputs : oWorksheet The worksheet to count the printed pages. 'Outputs : Returns the number of printed pages in the worksheet 'Author : Andrew Baker 'Date : 1/Aug/2001 'Notes : Replaces the function ExecuteExcel4Macro("Get.Document(50)") in Excel97/2000. Function WorksheetCountPages(oWorksheet As Excel.Worksheet) As Long Dim bPageBreaksVisible As Boolean 'Store the visible state of the page breaks bPageBreaksVisible = oWorksheet.DisplayPageBreaks WorksheetCountPages = (oWorksheet.VPageBreaks.Count + 1) * (oWorksheet.HPageBreaks.Count + 1) 'Restore the visible state of the page breaks oWorksheet.DisplayPageBreaks = bPageBreaksVisible End Function Sub Test() MsgBox "The active sheet has " & WorksheetCountPages(ActiveSheet) & " pages...", vbInformation End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder