0
我想在Excel VBA中編寫一個宏,它添加了一個圖表,然後想重新命名並編輯列的顏色,但不知何故它會引發調試錯誤。在Excel VBA中編輯和命名新添加的圖表
這是我的代碼。是否有人可以幫助我:
Sub Charts()
ActiveSheet.Shapes.AddCha rt.Select
ActiveChart.ChartType = xlColumnStacked100
ActiveChart.SetSourceData Source:=Sheets("Calculations").Range("A1:D11")
ActiveChart.Name = "MyChart"
ActiveChart.SeriesCollection(1).XValues = "=Data!$N$5:$N$14"
ActiveChart.SeriesCollection(3).Select
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
End With
ActiveChart.Legend.LegendEntries(2).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 192, 0)
.Transparency = 0
.Solid
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
End With
ActiveChart.Legend.LegendEntries(3).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
ActiveChart.SeriesCollection(3).Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
Selection.Delete
End Sub
感謝
哪一行產生錯誤,錯誤到底是什麼? – vacip
對於此:ActiveChart.Name =「MyChart」,錯誤是:指定的維度對當前圖表類型無效。 – user1778266
對於此:使用Selection.Format.Fill,錯誤是對象'ChartFormat'的方法'填充'失敗 – user1778266