更改一组形状的颜色而不选择(填充和文本)

时间:2016-10-07 19:43:22

标签: excel-vba excel-2010 vba excel

关于以下代码:

Sub Macro1 ()
   With ActiveSheet.Shapes.Range(Array("MyShapeGroup")) 
     .Fill.ForeColor.RGB = cPurp  ''cPurp is global constant
     .TextFrame.Characters.Font.ColorIndex = 2
   End With
End Sub

我可以只使用填充颜色的更改来执行宏,但是,当我添加文本颜色更改时,我会得到应用程序定义或对象定义的错误。

所以我尝试了这个:

Sub Macro1()
    With ActiveSheet.Shapes.Range(Array("MyShapeGroup")).ShapeRange
       .Fill.ForeColor.RGB = cPurp
       .TextFrame.Characters.Font.ColorIndex = 2
    End With
End Sub

哪个'对象不支持此属性或方法'在With行。

还试过这个:

Sub Macro1()
    With ActiveSheet.Shapes.Range(Array("MyShapeGroup"))
       .Fill.ForeColor.RGB = cPurp
       .ShapeRange.TextFrame.Characters.Font.ColorIndex = 2
    End With
End Sub

哪个'对象不支持此属性或方法'在.ShapeRange行。

还试过这个:

Sub Macro1 ()
    ActiveSheet.Shapes.Range(Array("MyShapeGroup")).Select
    With Selection.ShapeRange
        .Fill.ForeColor.RGB = cPurp ''cPurp is global constant
        .TextFrame.Characters.Font.ColorIndex = 2
    End With
End Sub

如何在不使用选择的情况下有效地完成填充颜色更改和文本颜色更改?

2 个答案:

答案 0 :(得分:1)

请尝试使用+-----------+---------------+------------+ | ticket_id | path_distance | path | +-----------+---------------+------------+ | 12 | 3 | 14,32,78 | +-----------+---------------+------------+ | 9 | 4 | 2,58,76,89 | +-----------+---------------+------------+ ... etc 属性:

TextFrame2.TextRange

答案 1 :(得分:1)

我不擅长VBA,但我认为这对我有用!

Sub test()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes("MyShapeGroup").GroupItems
        shp.Fill.ForeColor.RGB = RGB(255, 255, 0)
        shp.TextFrame.Characters.Font.Color = vbWhite
    Next
End Sub
相关问题