Thread: [Solved] Keeping Table on One Page
View Single Post
 
Old 04-12-2011, 08:37 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi SCMiller,

You need:
KeepWithNext = True.

However, the code could be greatly simplified:
Code:
Sub KeepRowsTogether()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
  oTbl.Range.Paragraphs.KeepWithNext = True
Next oTbl
End Sub
The problem with either approach, though, is that it forces the table to 'keep with next' with the first paragraph following it. What you need is for the last paragraph in each cell on the last row not to have the 'keep with next' attribute:
Code:
Sub KeepRowsTogether()
Dim oTbl As Table, oCel As Cell
For Each oTbl In ActiveDocument.Tables
  oTbl.Range.Paragraphs.KeepWithNext = True
  For Each oCel In oTbl.Rows.Last.Range.Cells
    oCel.Range.Paragraphs.Last.KeepWithNext = False
  Next oCel
Next oTbl
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote