Thread: [Solved] Keeping Table on One Page
View Single Post
 
Old 08-22-2016, 03:33 AM
andyroberts1234 andyroberts1234 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Dec 2015
Posts: 2
andyroberts1234 is on a distinguished road
Default Vertically merged cells cause runtime error

Hello,

I have been trying to run this code however come across the following error:

Runtime error 5991: Cannot access the individual rows of this collection because the table has vertically merged cells.

Is there a way to make it work with tables with merged cells, or if not to do something like 'if table has merged cells then skip the formatting of this table'?

For clarity, this is the code I am running:

Code:
Sub ApplyTableAttribute()
'
' ApplyTableAttribute Macro
'
'
Dim oTbl As Table, oCel As Cell
' for each table in the active document
For Each oTbl In ActiveDocument.Tables
'set paragraphs to keep with next
  oTbl.Range.Paragraphs.KeepWithNext = True
  ' for each cell in the last row of the table
  For Each oCel In oTbl.Rows.Last.Range.Cells
  ' 'set the last paragraph to not keep with next
    oCel.Range.Paragraphs.Last.KeepWithNext = False
  Next oCel
Next oTbl
End Sub
Thanks

Andy
Reply With Quote