Problem of HPageBreaks

L

Larry

Hello,

I try to access the Excel Worksheet’s HPageBreaks. I can get the COUNT of
the HPageBreaks. But when I start to loop the pagebreaks by using a integer
index and the index > 1, Microsoft.Office.Interop.Excel always give me error:
“invalid indexâ€(The object has 17 pagebreaks). It can get the first pagebreak
in the pagebreaks only, not the others.

Thanks,
Larry
 
M

macropod

Hi Larry,

How are you using HPageBreaks? You can iterate the counts using code like:

Sub PageBreakTest()
Dim i As Integer
With ActiveSheet
For i = 1 To .HPageBreaks.Count
If .HPageBreaks(i).Extent = xlPageBreakFull Then MsgBox "HPageBreak: " & i
Next
End With
End Sub

or

Sub PageBreakTest()
Dim HPB As HPageBreak
Dim i As Integer
With ActiveSheet
For Each HPB In .HPageBreaks
i = i + 1
If HPB.Extent = xlPageBreakFull Then MsgBox "HPageBreak: " & i
Next
End With
End Sub

Note: the 'extent' test is just there to demonstrate that you can do something with the HPageBreak.
 

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