View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JCIrish JCIrish is offline
external usenet poster
 
Posts: 39
Default return pageBreaks

Hi, NickHK
Thanks for the very useful response. I'm new at this. The last two lines of
my code were put there simply to let me step through it several times,
clearing the results and changing the HPageBreaks() subscript to observe the
results. I just wanted to know where all the page breaks occur. I see the
logic of what you've written and I will try that. I've not run into the code,
"Debug.Print", so, not yet having tried it, I don't know what it does. Ditto
for the line,"Next." Can you tell me something about these lines?

Again, thanks a lot for giving a rookie a hand.

JCIrish

"NickHK" wrote:

JCIrish,
Not sure what you are trying to achieve with the code but you will only be
to work with HPageBreaks(2), if it exists, hence the Subscript error.
To work with all Hbreaks:
Dim myHPageBreak As HPageBreak
For Each myHPageBreak In ActiveWorkbook.Worksheets(1).HPageBreaks
With myHPageBreak
Debug.Print "Manual ? : " & CBool(.Type = xlPageBreakManual)
Debug.Print "Location : " & .Location.Address(, , xlR1C1)
End With
Next
End Sub


"JCIrish" wrote in message
...

Here is a simple code I've written that returns page break locations, but
only those page breaks that I've inserted manually. It won't return page
breaks that Excel inserts automatically. If I try to get these page breaks

I
get the message, "subscript out of range. Can anybody tell me why? And how

to
use this type of simple code to get automatic page breaks?

Sub pageBreakA1C1()

'will find only those page breaks that were manually inserted
'won't find those inserted automaticall by Excel

Dim myPageBreakA1C1
myPageBreakA1C1 =
ActiveWorkbook.Worksheets(1).HPageBreaks(2).Locati on.Address(, , xlR1C1)
Range("A3").Select
Selection = myPageBreakA1C1
Range("A4").Select
Range("A3").ClearContents

End Sub