Get page address.

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
3,140
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
Code:
Sub Show_Page()
Dim sh1 As Worksheet, lc As Long
Set sh1 = Worksheets("Sheet1")
lc = sh1.Cells(1, sh1.Columns.Count).End(xlToLeft).Column
sh1.PageSetup.PrintArea = sh1.Range("A1:A" & sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row).Resize(, lc).Address
    With sh1
        .PrintOut 2, 2, , -1
    End With
End Sub

Above macro will just preview page2 of n pages.
Is it possible to get the address of that page2 range?

I know I can get it with HPageBreaks but that is not what I am after.
On my test workbook, page2 is A48:J94 and this address is what I am after.
If you could just change ".PrintOut 2, 2, , -1" to ".MsgBox 2, 2, , -1 .Address" that would be it!!!!!!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I don't know if there is an easy way or not.
Here is how you could find the page breaks, so you could do it "manually" since you know page 2 should be in between horizontal page breaks #1 and #2.
VBA Code:
Sub findBreaks()
' ---------------- Horizontal breaks
    hPB = 1
    r = 1
        Do While hPB <= 5 And r < 250
        If ActiveSheet.Rows(r).PageBreak = xlPageBreakAutomatic Then
            MsgBox "Found horizontal page break #" & hPB & " on row " & r
            hPB = hPB + 1
        End If
        r = r + 1
    Loop
    
' ---------------- Vertical breaks
    vPB = 1
    c = 1
        Do While vPB <= 5 And c < 100
        If ActiveSheet.Columns(c).PageBreak = xlPageBreakAutomatic Then
            MsgBox "Found vertical page break #" & vPB & " on column " & c
            vPB = vPB + 1
        End If
        c = c + 1
    Loop
End Sub
 
Upvote 0
@Engberg
Thank you for your answer.
I have that solution and I have been using it for quite a while. Obviously, it works as intended but I wondered if there was a way without using the page breaks.
As asked in my first post, it seems so close when you can do all kind of things with printout but not, at least I can't, what I want.
Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top