Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning page-count to a cell NAHolmes Excel Worksheet Functions 2 November 25th 09 09:11 AM
Page Count with Tabs tom Excel Discussion (Misc queries) 3 October 27th 06 04:09 AM
How do I remove the page count on work Freddyp1 Setting up and Configuration of Excel 1 September 8th 06 11:39 PM
Page Count pkferret Excel Discussion (Misc queries) 3 April 12th 06 03:19 PM
Excel Page count Tom Ogilvy Excel Programming 0 July 17th 03 03:06 PM


All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"