如何检测具有(水平)合并单元格的Word表格?

时间:2010-12-24 02:09:01

标签: ms-word word-vba

当Word表格包含水平合并的单元格时,访问aTable.Columns.First或通过aTable.Columns执行For Each将导致错误。

有没有办法确定表是否包含水平合并的单元格而不会导致错误?

我已阅读Determine if a Word cell is merged,但这是关于检测特定Word表格单元是否合并,而不是整个表格是否包含任何合并单元格。

2 个答案:

答案 0 :(得分:2)

this article中找到Table对象上的Uniform属性的引用,如果表已合并或拆分单元格,则返回false。

虽然这并不表示细胞是水平还是垂直合并(或两者),但它是一个开始,属性回答了我的问题。

答案 1 :(得分:0)

是的,它就在那里。                 以下是如何检测垂直合并单元格的逻辑解释。水平合并的单元格也可以检测,但需要更多的编码。

            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