Global inhibit "Allow row to break across pages"

N

NL_Derek

I have a Word document generated by another application (RoboHelp) which
contains some tables.
I do not want rows of these tables to break across pages; is there any way I
can globally clear the option Table > TableProperties > Row >
AllowRowToBreakAcrossPages.
At present I have to manually look for breaking rows and clear the option
manually each time.
I use Word 2003 under Windows XP

--- Derek
 
S

StevenM

To: NL Derek,

Try running one of the following macros.

'
' Keep a Table on same page
' Put cursor inside table and run this macro
'
Sub KeepTableOnOnePage()
Dim oTable As Table
Dim i As Long
Dim rows As Long

If Selection.Information(wdWithInTable) = False Then
MsgBox "The cursor must be positioned in the table."
Else
Set oTable = Selection.Tables(1)
oTable.rows.AllowBreakAcrossPages = False
rows = oTable.rows.Count - 1
For i = 1 To rows
oTable.rows(i).Range.ParagraphFormat.KeepWithNext = True
Next i
End If
End Sub

'
' 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

Steven Craig Miller
 
N

NL_Derek

Thanks Steven, you've put me on a good track. I made a macro as follows:

Sub ForceUnbrokenRows()

Dim ThisTable As Table
Dim TableNumber As Long
Dim RowNumber As Long

For TableNumber = 1 To ActiveDocument.Tables.Count
Set ThisTable = ActiveDocument.Tables(TableNumber)
For RowNumber = 1 To ThisTable.Rows.Count
ThisTable.Rows(RowNumber).AllowBreakAcrossPages = False
Next RowNumber
Next TableNumber

End Sub

.... and it worked until it encountered a table with vertically merged cells,
when I got error 5991 (Cannot access individual rows...)

Now very few tables in my project have vertically merged cells, so I can
afford to just skip such tables. But how do I detect this?
I guess I need to add something like:

If ThisTable.HasVerticallyMergedCells = True Then
Next TableNumber
Endif

I don't know VBasic so I don't know whether this is valid syntax. I looked
around in the object browser but couldn't find anything about vertical
merging.
Can you (or anyone else) please help?

--- Derek
 

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