query auto page breaks

rerickson

New Member
Joined
Dec 19, 2017
Messages
2
I need to determine where Excel will put automatic page breaks in a sheet where the #rows, and their heights, vary. Reading .PageBreak for every row turns out to be very slow! Is there a better way?

My sheets have several sections; we'd like to avoid page breaks within a section. Rows get deleted or hidden by macro, based on the data, when finalizing a sheet; I’ll set row.PageBreak =xlManual where a section would otherwise spill past the end of the page. (In Word this would be so easy...)

One solution is to scan through the rows, looking for .PageBreak = xlAutomatic. Surprisingly, this takes about 50 to 100ms per row! (Apparently Excel figures out the page layout with each fetch of the PageBreak property; ascending and descending order are equally slow.)

What to do instead? (Alas, sheet.VPageBreaks has only manual breaks, not the automatic ones.)

Alternatively, might it be possible to determine how far down the printed page a row will land? I could then compare that_position + range.RowHeight to PaperSize - margins.

This is with Office 2013.
Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Researching further, it seems that .VPageBreaks should contain both manual and automatic page breaks (and thus would be an efficient approach here), but that collection is not always populated, and it's not clear what will populate it! Some articles say you need to select the last cell, or scroll that cell into the window, or enter Print Preview mode; all those still leave me with ActiveSheet.VPageBreaks.Count =0.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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