当Word表格包含水平合并的单元格时,通过aTable.Columns访问aTable.Columns.First或执行For Each将导致错误。
有没有一种方法可以确定表格是否包含水平合并的单元格而不会导致错误?
我读过Determine if a Word cell is merged,但这是关于检测特定Word表格单元格是否合并,而不是整个表格是否有任何合并的单元格。
发布于 2011-01-04 07:41:38
在this article中找到了对表对象上的统一属性的引用,如果表合并或拆分了单元格,则该引用将返回false。
虽然这并不表示单元格是水平合并还是垂直合并(或两者都合并),但这是一个开始,该属性回答了我的问题。
发布于 2016-07-07 19:31:00
是的,它就在那里。以下是如何检测垂直合并单元格的逻辑解释。水平合并的单元也可以检测到,但需要更多的编码。
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
Shubhayanhttps://stackoverflow.com/questions/4523806
复制相似问题