Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Excel 2002 VBA code to return a page number within a worksheet

How do I write the code to return a page number within a given worksheet, so
that that number can be used (1) in an expression or (2) to cut, paste,
delete, etc the page? Also, the code to return the number of pages in a
worksheet? Thanks very, very much for any assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Excel 2002 VBA code to return a page number within a worksheet

Hi JCIrish

You can do this but it is not fast

This will give you the pages
pgnum = ExecuteExcel4Macro("Get.Document(50)")

This will copy the pages to another sheet
http://www.rondebruin.nl/hpagebreaks.htm


This give you the activecell page

Sub CurrentPage()
Dim VPC As Integer, HPC As Integer
Dim VPB As VPageBreak, HPB As HPageBreak
Dim NumPage As Integer

If ActiveSheet.PageSetup.Order = xlDownThenOver Then
HPC = ActiveSheet.HPageBreaks.Count + 1
VPC = 1
Else
VPC = ActiveSheet.VPageBreaks.Count + 1
HPC = 1
End If
NumPage = 1
For Each VPB In ActiveSheet.VPageBreaks
If VPB.Location.Column ActiveCell.Column Then Exit For
NumPage = NumPage + HPC
Next VPB
For Each HPB In ActiveSheet.HPageBreaks
If HPB.Location.Row ActiveCell.Row Then Exit For
NumPage = NumPage + VPC
Next HPB

MsgBox "Page number of the active cell = " & NumPage

' ActiveWindow.SelectedSheets.PrintOut _
' From:=NumPage, To:=NumPage, _
' Copies:=1, Collate:=True

End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"JCIrish" wrote in message ...
How do I write the code to return a page number within a given worksheet, so
that that number can be used (1) in an expression or (2) to cut, paste,
delete, etc the page? Also, the code to return the number of pages in a
worksheet? Thanks very, very much for any assistance.



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
Unique Footer for each page in worksheet with a page number Keys2thecitY Excel Worksheet Functions 0 September 7th 09 06:06 AM
Excel 2002 : How to reduce the number of unused worksheet ? Mr. Low Excel Discussion (Misc queries) 5 November 26th 07 07:46 PM
How to return the Number of shares for a given stock code for a given portfolio aray Excel Discussion (Misc queries) 1 May 18th 06 04:50 AM
Is there a function that will return the page number? garyme2 Excel Worksheet Functions 1 July 15th 05 12:15 AM
Return to previous worksheet after code pastes in another worksheet? Ron[_28_] Excel Programming 4 September 4th 04 07:52 PM


All times are GMT +1. The time now is 12:01 AM.

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

About Us

"It's about Microsoft Excel"