View Single Post
 
Old 06-05-2017, 04:34 PM
Jfedora Jfedora is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Jun 2017
Posts: 4
Jfedora is on a distinguished road
Default Removing KeepWithNext Formatting from Nested Tables?

Hello,
I have a document that is one big table with three Columns that has various other Tables within the middle Column. I am trying to remove Keep with next from the row in the larger all encompassing table that is above the smaller table, so that the tables don't split across pages. I used a macro that I found on here for a similar endeavor, just not in a giant table.

Code:
Public Sub KeepRowsTogether()
'Keeps Tables on one page
Dim oTbl As Table, oCel As Cell
'Iterate through all tables in document
For Each oTbl In ActiveDocument.Tables	
    oTbl.Range.Paragraphs.KeepWithNext = True
	With oTbl
	'If there are no merged vertical cells, turn off KeepWithNext on last row
    If .Uniform = True Then
      For Each oCel In .Rows.Last.Range.Cells
        oCel.Range.Paragraphs.Last.KeepWithNext = False
      Next oCel
    Else
	'Find vertically merged cells and turn off KeepWithNext 
      Set oCel = .Range.Cells(.Range.Cells.Count)
      Do While oCel.ColumnIndex > 1
        oCel.Range.Paragraphs.Last.KeepWithNext = False
        Set oCel = oCel.Previous
      Loop
      oCel.Range.Paragraphs.Last.KeepWithNext = False
    End If
  End With
Next oTbl
End Sub
I'm already parsing through all the tables like so:
Code:
'Loops through all tables in large Table
For Each InnerTable In OutterTable.Tables
	InnerTable.PreferredWidthType = wdPreferredWidthPoints
	InnerTable.PreferredWidth = 400
I was wondering if anyone could help me with how to get this formatting changed. Thanks

Last edited by Jfedora; 06-06-2017 at 10:53 AM.
Reply With Quote