2017-06-27 49 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