Keep with next

M

mike

I create several hundred different sized tables in a document, none more
than 12 rows and I don't want any of them to span a page break. I
usually go through after and select the offending tables and apply keep
with next. I'd like to programmatically apply keep with next.

Any ideas?

thanks
Mike
 
S

StevenM

To: Mike,

'
' Keep Each Table On One Page
'
Sub KeepEachTableOnOnePage()
Dim oTable As Table
Dim i As Long
Dim nTables As Long
Dim nNum As Long

nTables = ActiveDocument.Tables.count
If nTables = 0 Then Exit Sub
For nNum = 1 To nTables
Application.StatusBar = nTables & ":" & nNum
Set oTable = ActiveDocument.Tables(nNum)
oTable.rows.AllowBreakAcrossPages = False
For i = 1 To (oTable.rows.count - 1)
oTable.rows(i).Range.ParagraphFormat.KeepWithNext = True
Next i
Next nNum
End Sub

If this doesn't work exactly as you like, let me know.

Steven Craig Miller
 
M

mike

Thanks Steven,

works great!

Mike
To: Mike,

'
' Keep Each Table On One Page
'
Sub KeepEachTableOnOnePage()
Dim oTable As Table
Dim i As Long
Dim nTables As Long
Dim nNum As Long

nTables = ActiveDocument.Tables.count
If nTables = 0 Then Exit Sub
For nNum = 1 To nTables
Application.StatusBar = nTables & ":" & nNum
Set oTable = ActiveDocument.Tables(nNum)
oTable.rows.AllowBreakAcrossPages = False
For i = 1 To (oTable.rows.count - 1)
oTable.rows(i).Range.ParagraphFormat.KeepWithNext = True
Next i
Next nNum
End Sub

If this doesn't work exactly as you like, let me know.

Steven Craig Miller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top