PDA

View Full Version : [SOLVED:] Merged Cell over Page Break is not Displayed properly



ArneG
07-06-2022, 08:02 AM
Hey there,

i have noticed an odd behavior, when it comes to tables with vertically merged Cells and when they hit the "page break". The attached picture illustrates the table structure. It can be seen, that the last "entry" in "Programmiersprachen" is not displayed.

One note: I cannot provide more data as below. If the code, the dotx template file is needed, than I have to write some generic.

The table is build by VBA code + "template table" that serves as style blueprint, including Properties as

Table.AllowPageBreaks = True
Rows.AllowBreakAcrossPages = 0 (turns out, that this property does not have any effect the observed behavior)


The table's content originates from a Access record set.

All in all the table looks fine, but this little thing keeps me in trouble.

From what I understand so far, is that Word "looses" the ability to address individual rows, when one starts to merge cells vertically (same goes for columns an horizontal merged cells). I have tried to "fill" additional Rows at this position, but failed, since I cannot execute Table.Rows.Add() or Table.Cell(x,y).Split. A Table.Split looks like an option, too. But the line of code always raise the error, that the object was already deleted (what ever that means in this situation). If I add a row before I merge all the cells, than I get trouble with my cell merging routines. Those routines rely on the specific table structure. An additional row would mean I have to put a lot more code in there to cope with that.

Is there any "self healing" feature for that, that I have overseen so far? I would love to :-)

Regards
Arne

Logit
07-06-2022, 07:29 PM
Not certain this will work but try "merge across" instead of "merge".

However, the best approach is to never utilize any 'merging' at all. It will always, at some point, get you in trouble. Truly.

macropod
07-06-2022, 11:25 PM
If your table has 'around' text wrapping, revert to 'none'.

Additionally, use :
• 'keep together' paragraph formatting on all paragraphs in the merged cells; and
• 'keep with next' paragraph formatting on all paragraphs except the last in the merged cells.

ArneG
07-07-2022, 01:32 AM
Not certain this will work but try "merge across" instead of "merge".
The Cell(s) in question are already merged "row-wise". Sorry, had to mentioned it earlier.


However, the best approach is to never utilize any 'merging' at all. It will always, at some point, get you in trouble. Truly.
Well, yes. I could do that. But it also means throwing away a big bunch of work (solving this particular problem not included). I would like to try a few things, before redesign the table structure and work around thereby a MS Word shortcoming.


If your table has 'around' text wrapping, revert to 'none'.
Since I could not find such a property for the table object, but for rows, I guess you mean it that way. If not, correct me please.
Row-Setting is


Table.Rows.WrapAroundText = False ' (or '0')



Additionally, use :
• 'keep together' paragraph formatting on all paragraphs in the merged cells; and
• 'keep with next' paragraph formatting on all paragraphs except the last in the merged cells.

I've tried it. But no luck. The behavior does not change


For i = startRow To endRow
tbl.Cell(i, 2).Merge MergeTo:=tbl.Cell(i + 1, 2)
If endRow - i >= 4 Then ' do it for all, but the last
tbl.Cell(i, 2).Range.ParagraphFormat.KeepTogether = True
tbl.Cell(i, 2).Range.ParagraphFormat.KeepWithNext = True
End If
i = i + 1
Next i

I will experiment with some other ideas. Maybe I find something that keeps my current structure and looks still good. But I would still love to solve the display issue programmatically. And not with some hacky workarounds :-)

macropod
07-07-2022, 02:03 AM
It would be much easier to resolve this problem if we had access to the actual document, rather than just a screenshot. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

ArneG
07-07-2022, 02:33 AM
It would be much easier to resolve this problem if we had access to the actual document, rather than just a screenshot. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

Okay, I stripped one down to relevant data.

macropod
07-07-2022, 04:07 AM
Perhaps:

Sub TblFormat()
Application.ScreenUpdating = False
Dim r As Long, x As Long, y As Long, z As Long
With ActiveDocument.Tables(1).Range
y = .Characters.First.Information(wdActiveEndPageNumber)
For x = 1 To .Cells.Count
If .Cells(x).ColumnIndex = 1 Then
z = .Cells(x).Range.Information(wdActiveEndPageNumber)
If y = z Then r = x
End If
If y < z Then
.Cells(r).Range.ParagraphFormat.PageBreakBefore = True
r = x: y = y + 1: z = y
End If
Next
End With
Application.ScreenUpdating = True
End Sub

ArneG
07-07-2022, 05:07 AM
Perhaps:

Sub TblFormat()
Application.ScreenUpdating = FalseDim r As Long, x As Long, y As Long, z As Long
With ActiveDocument.Tables(1).Range
y = .Characters.First.Information(wdActiveEndPageNumber)
For x = 1 To .Cells.Count
If .Cells(x).ColumnIndex = 1 Then
z = .Cells(x).Range.Information(wdActiveEndPageNumber)
If y = z Then r = x
End If
If y < z Then
.Cells(r).Range.ParagraphFormat.PageBreakBefore = True
r = x: y = y + 1: z = y
End If
Next
End With
Application.ScreenUpdating = True
End Sub

That works like a charm! And since this Sub pushes the whole "section" (roughly defined by column 1) to the next page is even more charming!

Thanks a lot. Its much appreciated!