Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > capturing the page number


Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2012, 06:44 PM
Heyjoe Heyjoe is offline
Centurion
 
Join Date: Nov 2006
Location: USA
Posts: 166
Default capturing the page number


Suppose I have a workbook with four worksheets. Table of contents, introduction, schedule 1 and schedule 2. If I do a print preview of the entire workbook, schedule 1 would begin on page 5. Is there any way to have a variable in vba capture that schedule 1 begins on page 5?
Reply With Quote
  #2  
Old 03-31-2012, 09:41 PM
_Mordred_'s Avatar
_Mordred_ _Mordred_ is offline
Freshman
 
Join Date: Jun 2011
Posts: 26
Default

Hi Heyjoe, I recorded the following
Code:
ActiveWindow.SelectedSheets.PrintOut From:=5, To:=5, Copies:=1, Collate _
        :=True, IgnorePrintAreas:=False
Reply With Quote
  #3  
Old 04-01-2012, 06:28 AM
Heyjoe Heyjoe is offline
Centurion
 
Join Date: Nov 2006
Location: USA
Posts: 166
Default

Thank you. Your macro would enable me to print page 5. But can I get the 5 into a variabe?
Reply With Quote
  #4  
Old 04-01-2012, 03:26 PM
_Mordred_'s Avatar
_Mordred_ _Mordred_ is offline
Freshman
 
Join Date: Jun 2011
Posts: 26
Default

Do you mean something like:
Code:
Dim pgNo As Long
   pgNo = 5
and then something like
Code:
ActiveWindow.SelectedSheets.PrintOut From:=pgNo,To:=pgNo
Reply With Quote
  #5  
Old 04-01-2012, 04:50 PM
Heyjoe Heyjoe is offline
Centurion
 
Join Date: Nov 2006
Location: USA
Posts: 166
Default

I do not want to put the page numbers in the code. I want vba to tell me what the first page number of each schedule is. For example the table of contents starts with page 1. The introduction starts with page 2. Schedule 1 starts with page 5 and schedule 2 starts with page 9.
Reply With Quote
  #6  
Old 04-01-2012, 08:53 PM
Kluz's Avatar
Kluz Kluz is offline
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,332
Default

Loop through the sheets using:
Code:
Thisworkbook.Sheets.Item(number_variable)
Looking for whatever you need to to determine the start of a schedule, exit the loop when you find it, and your variable will have the Item number of that sheet. Or, you could continue the loop and put the Item number into an array variable.
__________________
No the other right mouse click
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->