Consulting

Results 1 to 8 of 8

Thread: Merged Cell over Page Break is not Displayed properly

  1. #1
    VBAX Regular
    Joined
    Jul 2022
    Posts
    7
    Location

    Merged Cell over Page Break is not Displayed properly

    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
    Attached Images Attached Images
    Last edited by ArneG; 07-06-2022 at 08:12 AM.

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    575
    Location
    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.

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,413
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    VBAX Regular
    Joined
    Jul 2022
    Posts
    7
    Location
    Quote Originally Posted by Logit View Post
    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.

    Quote Originally Posted by Logit View Post
    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.

    Quote Originally Posted by macropod View Post
    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')

    Quote Originally Posted by macropod View Post
    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 :-)

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,413
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Regular
    Joined
    Jul 2022
    Posts
    7
    Location
    Quote Originally Posted by macropod View Post
    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.
    Attached Files Attached Files

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,413
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Regular
    Joined
    Jul 2022
    Posts
    7
    Location

    Thumbs up Thats it!

    Quote Originally Posted by macropod View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •