Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用合并的单元格调整表格标题颜色_Vba_Ms Word - Fatal编程技术网

Vba 使用合并的单元格调整表格标题颜色

Vba 使用合并的单元格调整表格标题颜色,vba,ms-word,Vba,Ms Word,我有大量的报告,其中有多个表需要调整标题颜色。但是,我遇到了一个问题,表的标题中垂直合并了单元格。代码如下: 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 m

我有大量的报告,其中有多个表需要调整标题颜色。但是,我遇到了一个问题,表的标题中垂直合并了单元格。代码如下:

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
属性,因此表格中每个单元格的
样式循环无法工作


还有别的办法吗?是否可以直接编辑表格样式?

表格对象没有单元格属性,但table.Range对象有,因此:

For Each cel in Table.Range.Cells
应:

Sub LoopCellsInTableWithMergedCells()
    Dim tbl As word.Table
    Dim cel As word.Cell

    Set tbl = ActiveDocument.Tables(1)
    For Each cel In tbl.Range.Cells
        Debug.Print cel.rowIndex, cel.ColumnIndex
    Next
End Sub