print preview range

S

sali

is there easy way to calculate cell ranges belonging to each printed page
[with current selected printer and current page setup]?
i mean, to know like print preview knows [by bordering with dashed lines]
which part of sheet will be printed on which separate page

suppose such function, say "getprintedpagelayout()" should return an array
of ranges, for each resulting page, like:
arr=array("a1:m50","a51:m100","a101:m150")
for three pages print.

any hint?

thnx
 
T

Tom Ogilvy

This should be a start:

Sub CountPageBreaks()
Dim vBrks() As Long
Dim hBrks() As Long
Dim varRow As Variant
Dim varCol As Variant
Dim Flag As Boolean
Dim i As Long
Dim k As Long
ActiveSheet.DisplayPageBreaks = True
ActiveSheet.Names.Add Name:="hpgBrk", _
RefersTo:="=Get.Document(64,""" & ActiveSheet.Name & """)"
ActiveSheet.Names.Add Name:="vpgBrk", _
RefersTo:="=Get.Document(65,""" & ActiveSheet.Name & """)"
On Error Resume Next
Flag = True
i = 1
While Flag
varRow = Application.Index(Evaluate(ActiveSheet.Name & _
"!hpgBrk"), i)
If Not IsError(varRow) Then
ReDim Preserve hBrks(1 To i)
hBrks(i) = varRow
i = i + 1
Else
Flag = False
End If
Wend
Flag = True
i = 1
While Flag
varCol = Application.Index(Evaluate(ActiveSheet.Name & _
"!vpgBrk"), i)
If Not IsError(varCol) Then
ReDim Preserve vBrks(1 To i)
vBrks(i) = varCol
i = i + 1
Else
Flag = False
End If
Wend
Debug.Print "rows: "
For k = LBound(hBrks) To UBound(hBrks)
Debug.Print k, hBrks(k)
Next
Debug.Print "Columns: "
For k = LBound(vBrks) To UBound(vBrks)
Debug.Print k, vBrks(k)
Next
End Sub


hth,
Tom Ogilvy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top