How to identify a particular vertically merged cell

J

Jeff Hall

I need to be able to identify a particular type of vertically merged cell

It's a cell that "looks" like it's the last cell in a table, but in the
table object its NOT the last cell. Here is a picture of a typical example
(better viewed in fixed width font)

--------------
| 1 | 2 | 3 |
|--------| |
| 4 | 5 | |
--------------

It's cell 3 in the above table which merges vertically down to what would
have otherwise been the last cell, - cell 6.

I cannot determine an elegant method or even a kludge.

The nearest I got to it was a kludge which selected the last character in
each cell and move down one line. If the cursor is then not "wdWithinTable"
it's either the last cell in the table or a cell of the type I'm looking
for. The trouble is that this works fine when manually applying the method
to a document but when executed in code, the cursor "disappears into the
ether" from cell 3.

This is vitally important to solve or my project has failed.
 
J

Jezebel

Not sure what counts as 'identify' here, but you can create a map of your
table by iterating the table range cells collection and checking the
RowIndex and ColIndex properties of each cell --

Dim pCell as Word.Cell
For each pCell in MyTable.Range.Cells
... debug.print Cell.RowIndex, Cell.ColIndex
Next

For some purposes you can use a cell's .Next property. For example, in your
table you might use something like

Set pCell = Table.Cells(2,2)
if pCell.Next.RowIndex > pCell.RowIndex then .... 'No column 3 in this
row
 
J

Jeff Hall

Thanks Jezebel but that doesn't solve the problem.
Not sure what counts as 'identify'

I need to know that cell 3 is a vertically merged cell. I prescan every
cell in the table and store information about each cell in an array.

Yes, I have examined all the table/row/column/cell properties and have an
algorithm that can identify any vertically merged cell except this special
case of a cell that looks like it's the last cell in the table (but isn't).

The ".Next" cell for cell3 is cell4 regardless of whether it's vertically
merged, so that won't help. Cell 3's coordinates are (row1,col3) but again
that does not help

--------------
| 1 | 2 | 3 |
|--------| |
| 4 | 5 | |
--------------

Do you have any other suggestions?

--------------------------------------------------------------------
Jeff Hall
--------------------------------------------------------------------
Not sure what counts as 'identify' here, but you can create a map of your
table by iterating the table range cells collection and checking the
RowIndex and ColIndex properties of each cell --

Dim pCell as Word.Cell
For each pCell in MyTable.Range.Cells
... debug.print Cell.RowIndex, Cell.ColIndex
Next

For some purposes you can use a cell's .Next property. For example, in
your
table you might use something like

Set pCell = Table.Cells(2,2)
if pCell.Next.RowIndex > pCell.RowIndex then .... 'No column 3 in this
row
 
J

Jeff Hall

OK I finally found a way to do it
The algorithm is this:

1. Copy the table to a new blank document
2. Delete all cell contents leaving an empty table frame
3. For each cell in the table...
3a. select the end of the cell
3b. move down one line
if still within the table
if the new row number is more than one larger than the
original cell's row number then it was a merged cell
else
if (wdMaximumNumberOfRows - OriginalCellRowNumber) >1
then it was a merged cell
4. Close the temporary document and activate the original document


What a kludge
 

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