【发布时间】:2020-07-05 02:57:14
【问题描述】:
我有大量的报告,其中包含多个需要调整标题颜色的表格。不过,我遇到了在标题中垂直合并单元格的表格的问题。代码如下:
Sub Recolor_Table()
Dim Doc_Table As Table
For Each Doc_Table In ActiveDocument.Tables
If Doc_Table.Style Like "*Non-Results Table*" Then
'Since this will match "*Results Table*" as well, check it first
Doc_Table.Rows(1).Shading.BackgroundPatternColor = 12566463 'Grey
ElseIf Doc_Table.Style Like "*Results Table*" Then
Doc_Table.Rows(1).Shading.BackgroundPatternColor = 8406272 'Blue
End If
Next Doc_Table
End Sub
此操作失败并显示以下错误消息:
运行时错误“5991”:
无法访问此集合中的各个行,因为表格有垂直合并的单元格
我尝试通过表格中的每个单元格调整为循环,但发现 word 中的表格没有.cells 属性,因此For each cell in table.cells 样式循环不起作用。
还有其他方法可以做到这一点吗?可能直接编辑表格样式?
【问题讨论】: