I understand HPageBreaks gives you the last page break available, but if there is only one sheet it won't give you a page break. My fix for this is to keep entering data into row after row of my sheet until a new page break occurs, then grab that row.
The problem is that HPageBreaks keeps telling me my page break is at, lets say, A30. When in reality its at A44. I've tried HPageBreaks a couple different ways but it keeps finding row 30 and not row 44.
I think the reason may be that my Excel document has taller row heights, because if I put my code in a program where the Excel row heights are all normal, then it works perfectly.
I do not know how to fix this so HPageResult will find the correct page break row, no matter how tall my rows are.
Code below:
The problem is that HPageBreaks keeps telling me my page break is at, lets say, A30. When in reality its at A44. I've tried HPageBreaks a couple different ways but it keeps finding row 30 and not row 44.
I think the reason may be that my Excel document has taller row heights, because if I put my code in a program where the Excel row heights are all normal, then it works perfectly.
I do not know how to fix this so HPageResult will find the correct page break row, no matter how tall my rows are.
Code below:
Code:
'i has my last row of data.
i += 2
Dim iStart As Integer = i 'hold this row so we can clear what we are about to do
Dim pgBreaks As Integer = oSheet1.HPageBreaks.Count 'current # of page breaks
Do Until oSheet1.HPageBreaks.Count > pgBreaks
'Keep adding a row of data until we reach a page break
oSheet1.Range("A" & i).Value = "fill"
i += 1
Loop
oSheet1.Range("A" & iStart & ":A" & i).ClearContents() 'get rid of all the "fill"s you just inserted
Dim LastRow As Integer = i - 2 'we will be in the second row of the new page, so move up
i = LastRow