2017-06-27 53 views
0
rgb1 = 200 
rgb2 = 200 
rgb3 = 200 

ActiveChart.ChartArea.Select 
With ActiveSheet.Shapes("Chart 1").Fill 
    .Visible = msoTrue 
    .ForeColor.RGB = RGB(rgb1, rgb2, rgb3) 
    .Transparency = 0 
    .Solid 
End With 

当我在Excel 2010上面录制宏是我所得到的,当在图表区域是的最外层部分右击图表。这是ActiveChart.PlotArea.Select以外的区域。Excel生成VB ActiveSheet.Shapes(“图1”),填写运行时错误

然而,当我尝试使用上面的代码在我的数据绘制的宏它然后失败runtime error '-2147024809 (80070057)': the item with the specified name wasn't found

我坚持的("Chart 1")部分。 我可以有任何数量的图表已经在Excel中创建,有任何种类的名称,只要我在它上面记录一个宏导致相同的宏代码。

在excel visual basic中,如何将图表区域背景颜色更改为活动图表的指定rgb值?

回答

1

您可以使用With ActiveChart.ChartArea.Format.Fill如下...

rgb1 = 200 
rgb2 = 200 
rgb3 = 200 

With ActiveChart.ChartArea.Format.Fill 
    .Visible = msoTrue 
    .ForeColor.RGB = RGB(rgb1, rgb2, rgb3) 
    .Transparency = 0 
    .Solid 
End With 
+0

感谢,这工作 – ron