0

I'm currently using Microsoft Word 2016 VBA to programmatically set the AllowBreakAcrossPages setting so that if a row's contents overlaps the footer contents, I toggle the setting so that the row can break across pages. To solve this issue, I'm thinking about looping through all the cells of each table in the document and get the wdVerticalPositionRelativeToPage.Information of the last characters in each cell and comparing it to the footer's height relative to the page. If the last character's height is greater than the footer's, I set the row to break across pages. You can imagine that this is taking a while in a document that has many tables and cells. Is there a more efficient way to know if the row contents overlap the footer contents than looping through each cell in the row to see if a cell is causing the row to overlap the footer?

I tried using the row height property but discovered that if the HeightRule property of the specified row is wdRowHeightAuto then that means I can't access the row height via VBA.

I discovered that it's possible to use wdVerticalPositionRelativeToPage.Information with a row by row comparison of the prior and next rows like described in another posting - https://stackoverflow.com/a/14753231/4372244.

The only problem with that solution is that it doesn't work for the last row in a table or if it's the last row on a page.

Therefore, I'm examining a cell by cell solution.

braX
  • 11,506
  • 5
  • 20
  • 33
  • Why not simply set that as the default for all of your rows except the header? – Charles Kenyon Feb 11 '23 at 18:31
  • I'd rather have the AllowBreakAcrossPages setting to be toggled for everything; I'm working on something with the constraint of not enabling AllowBreakAcrossPages for all rows, only those that are too large to properly fit and not overlap the footer. – programmingnovice Feb 11 '23 at 21:24
  • 1
    That is the purpose, in general, of this setting, isn't it? This setting should only break rows that will not fit on the page. Unless your row is too big for the space available on the page, it will not break. If you have this disabled, the table will break before the row. – Charles Kenyon Feb 12 '23 at 00:06
  • I realized that other settings were enabled that prevented the table from breaking and overlapping the footer even if the setting was disabled. Thanks for pointing that out in your last sentence of your reply. For those who experience this problem in the future, see https://answers.microsoft.com/en-us/msoffice/forum/all/word-tables-overlapping-footer-and-strange/5b0c6752-47b6-4bc4-bb50-5fb597360266. – programmingnovice Feb 12 '23 at 01:39

0 Answers0