Error 5991 - "table has vertically merged cells" - How can I unmer

M

Maxer

I have VBA code in word that is going to each table in the word document,
then doing some testing, then moving to each row in the word document, then
finally to each cell.

Once it finishes its tests it moves them over into an Excel worksheet.

Now the process works perfectly for my needs, until I hit a table that has
vertically merged cells.

At my:
------
Set oRows = oTable.Rows
For Each oRow in oRows
'do stuff'
Next oRow
-----
part of the code as soon as it gets to "For Each oRow in oRows" then it
throws up the 5991 error:

Run-time error '5991':
Cannot access individual rows in this collection because the table has
vertically merged cells.


I badly need some way to programmatically split those merged cells.

I actually don't even want those merged cells, they are just the first part
of several tables in the word document. I don't really start moving any data
around until I get a few rows into the table (though the row number varies
table by table).

Anyway, does anyone know of a way I can either test for vertically merged
cells and then just skip to the "Next oRow" or if I can't do that then split
them so that it doesn't stop my code from completing it's processing?

Sadly I can't unmerge them by hand as there are thousands of tables in this
word document and a hundred or so have these merged cells.

Thank you for your help.
 
J

Jean-Guy Marcil

Maxer was telling us:
Maxer nous racontait que :
I have VBA code in word that is going to each table in the word
document, then doing some testing, then moving to each row in the
word document, then finally to each cell.

Once it finishes its tests it moves them over into an Excel worksheet.

Now the process works perfectly for my needs, until I hit a table
that has vertically merged cells.

At my:
------
Set oRows = oTable.Rows
For Each oRow in oRows
'do stuff'
Next oRow
-----
part of the code as soon as it gets to "For Each oRow in oRows" then
it throws up the 5991 error:

Run-time error '5991':
Cannot access individual rows in this collection because the table has
vertically merged cells.


I badly need some way to programmatically split those merged cells.

I actually don't even want those merged cells, they are just the
first part of several tables in the word document. I don't really
start moving any data around until I get a few rows into the table
(though the row number varies table by table).

Anyway, does anyone know of a way I can either test for vertically
merged cells and then just skip to the "Next oRow" or if I can't do
that then split them so that it doesn't stop my code from completing
it's processing?

Sadly I can't unmerge them by hand as there are thousands of tables
in this word document and a hundred or so have these merged cells.

Thank you for your help.

If you use a Range object, you can access all the cells, even if they are
merged:

Dim oTableRge As Range
Dim oCell As Cell

Set oTableRge = ActiveDocument.Tables(1).Range

For Each oCell In oTableRge.Cells
MsgBox oCell.Range.Text
Next



--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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