问题
When a Word table contains horizontally merged cells, accessing aTable.Columns.First or performing a For Each over aTable.Columns will result in an error.
Is there a way to determine if a table contains horizontally merged cells without resulting in an error?
I've read Determine if a Word cell is merged, but that is about detecting if a particular Word table cell is merged, rather than does the whole table have any merged cells.
回答1:
Found a reference in this article to a Uniform property on the Table object, which will return a false if the table has merged or split cells.
Though this does not indicate if the cells are horizontally or vertically merged (or both), but it's a start, and the property answers my question.
回答2:
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
Shubhayan
来源:https://stackoverflow.com/questions/4523806/how-do-i-detect-a-word-table-with-horizontally-merged-cells