View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
S N S N is offline
external usenet poster
 
Posts: 16
Default how to count number of pages in worksheet

and i dont want to copy the function or code on all worksheets in my
workbooks. i would like to use something like code in a module file.

i would like to have a general code which i can use in all worksheets of my
workbooks

please help.

"Rick Rothstein (MVP - VB)" wrote in
message ...
I am reading your question differently than Nate did... it looks to me like
you want to know how many pages it will take to print out the worksheet
itself (not how many worksheets are in the workbook). If I am right,
copy/paste the following code into the code window for the worksheet you
want this functionality on (right click the worksheet's tab and select View
Code from the popup menu that appears)....

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
Range("A1").Value = ExecuteExcel4Macro("GET.DOCUMENT(50)")
Whoops:
Application.EnableEvents = True
End Sub

Rick


"NateBuckley" wrote in message
...
Hello I hope this helps, go to the code in ThisWorkBook.

You can do this by pushing ALT+F11 then right clicking on "ThisWorkBook"
on
the left, and left clicking on view code.

Then paste in the following

Private Sub Workbook_Open()
Sheets("NameOfSheet").Cells(1, 1).Value = Worksheets.Count
End Sub

When the worksheet opens it'll count the number of worksheets and put
this
value in a specified cell. So in this case if you had a sheet named
NameOfSheet it would put a number in Row 1, Column A.

Hope this helped.

"msnews" wrote:

i want to insert the count of total number of pages of a worksheet in a
cell
of the same worksheet.
this should be done automatically using worksheet formula or visual
basic
code or macro.
please help