Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Page count
One way:
Public Function NumPagesInWorkbook( _ Optional ByRef wkBook As Workbook) As Integer Dim wkSht As Worksheet If wkBook Is Nothing Then Set wkBook = ActiveWorkbook For Each wkSht In wkBook.Worksheets With wkSht If Application.CountA(.Cells) Then NumPages = NumPages + _ (.HPageBreaks.Count + 1) * _ (.VPageBreaks.Count + 1) End If End With Next wkSht End Function In article , "Joe" wrote: Would anybody have some example code that shows count the number of pages that are shown in the page break preview in Excel? I am trying to get page counts from different office files by looping thru a column in Excel that contains file names. When I find an Excel file, I want to count the number of pages that will be displayed in the page break preview view. Thanks Joe. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Page count
Where are you running the code from? Sounds like you are running it from
excel. If so, why all the createobject stuff? If your document is opened in another instance of excel, then your code is looking at the instance of excel where the code is contained. ex. Instance1, the instance of excel where the workbook with the code is. Instance2, the instance where you open workbook "loc" Your page counting code is working on the activeworkbook in instance 1. There is no reason to have two instances. Regards, Tom Ogilvy Joe wrote in message ... Here is my code. All I get is zero's. Case "xls" 'MS Excel Set AppObject = CreateObject ("Excel.Application") AppObject.Visible = True AppObject.Workbooks.Open Filename:=loc 'numPages = Application.ExecuteExcel4Macro("Get.Document(50)") Dim wkSht As Worksheet Dim wkBook As Workbook If wkBook Is Nothing Then Set wkBook = ActiveWorkbook For Each wkSht In wkBook.Worksheets With wkSht If Application.CountA(.Cells) Then NumPages = NumPages + _ (.HPageBreaks.Count + 1) * _ (.VPageBreaks.Count + 1) End If End With Next wkSht AppObject.Quit Cells(Count1, 2).Value = PageCount Any ideas? -----Original Message----- One way: Public Function NumPagesInWorkbook( _ Optional ByRef wkBook As Workbook) As Integer Dim wkSht As Worksheet If wkBook Is Nothing Then Set wkBook = ActiveWorkbook For Each wkSht In wkBook.Worksheets With wkSht If Application.CountA(.Cells) Then NumPages = NumPages + _ (.HPageBreaks.Count + 1) * _ (.VPageBreaks.Count + 1) End If End With Next wkSht End Function In article , "Joe" wrote: Would anybody have some example code that shows count the number of pages that are shown in the page break preview in Excel? I am trying to get page counts from different office files by looping thru a column in Excel that contains file names. When I find an Excel file, I want to count the number of pages that will be displayed in the page break preview view. Thanks Joe. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Returning page-count to a cell | Excel Worksheet Functions | |||
Page Count with Tabs | Excel Discussion (Misc queries) | |||
How do I remove the page count on work | Setting up and Configuration of Excel | |||
Page Count | Excel Discussion (Misc queries) | |||
Excel Page count | Excel Programming |