Discussion:
How to recognize merged cells in a table? help!!!!!
(too old to reply)
s***@gmail.com
2016-07-07 11:28:06 UTC
Permalink
Yes, it's there. Here is the logical explanation how you will detect vertically merged cells. Horizontally merged cell also can detect, but it will need some more coding.

But, unfortunately, not by calling any WORD VBA method or accessing any property of cell or table. It's by applying successive steps.

Step1:
-> Detect Row Count and Column Count of the table

Step2:
-> Declare an string array with same dimension as table( Dim A$()). Fill each cell of the array with "<m>" string.

Step3:
-> Start from cell(1)
-> Then move cell by cell(Cell.Next method)
-> Get each cells RowIndex and ColumnIndex.
-> Erase the content "<m>" from the array, referenced by this RowIndex and ColumnIndex(A(RowIndex,ColumnIndex)=""
-> Repeat this step until Cell.Next ends.

Step4:
-> Now check each cell of the Array(A$()). Those cells have the"<m>" string, are merged. Merged with immediate top cell.

I've not placed any function or code block. Assume it'll be more easy.

Thanks
g***@gmail.com
2017-09-24 21:08:57 UTC
Permalink
Makes sense.
Let me try.

I have a bit dirty solution for accessing text in table that contains merged cells. MS Word and matching VBS are here:
http://www.burlingtonvisionandlab.com/Downloads/AccesTextInMergedCells/
j***@gmail.com
2017-10-15 16:29:26 UTC
Permalink
Post by s***@gmail.com
Yes, it's there. Here is the logical explanation how you will detect vertically merged cells. Horizontally merged cell also can detect, but it will need some more coding.
But, unfortunately, not by calling any WORD VBA method or accessing any property of cell or table. It's by applying successive steps.
-> Detect Row Count and Column Count of the table
-> Declare an string array with same dimension as table( Dim A$()). Fill each cell of the array with "<m>" string.
-> Start from cell(1)
-> Then move cell by cell(Cell.Next method)
-> Get each cells RowIndex and ColumnIndex.
-> Erase the content "<m>" from the array, referenced by this RowIndex and ColumnIndex(A(RowIndex,ColumnIndex)=""
-> Repeat this step until Cell.Next ends.
-> Now check each cell of the Array(A$()). Those cells have the"<m>" string, are merged. Merged with immediate top cell.
I've not placed any function or code block. Assume it'll be more easy.
Thanks
I found this thread when looking for the same answer for PowerPoint and based on your idea, I write this to output the merged state of any cells in a table to the Immediate window:

' Written by Jamie Garroch of YOUpresent.co.uk
' Purpose : Displays the merged state of cells in a table
Public Sub DetectMergedCells()
Dim lRow As Long, lCol As Long
Dim arrMerged() As String
With ActiveWindow.Selection.ShapeRange(1).Table
ReDim arrMerged(.Rows.Count, .Columns.Count)
For lRow = 1 To .Rows.Count
For lCol = 1 To .Columns.Count
.Cell(lRow, lCol).Select
arrMerged(lRow, lCol) = IIf(MultipleCellsSelected, "[m]", "[ ]")
Next
Next
For lRow = 1 To .Rows.Count
For lCol = 1 To .Columns.Count
Debug.Print arrMerged(lRow, lCol);
Next
Debug.Print
Next
End With
End Sub

' Supporting function for DetectMergedCells
' Determines if currently selected cell is actually more than a single cell i.e. merged
Private Function MultipleCellsSelected() As Boolean
Dim lRow As Long, lCol As Long
Dim counter As Long
With ActiveWindow.Selection.ShapeRange(1).Table
For lRow = 1 To .Rows.Count
For lCol = 1 To .Columns.Count
If .Cell(lRow, lCol).Selected Then counter = counter + 1
Next
Next
End With
If counter > 1 Then MultipleCellsSelected = True
End Function

Loading...