用颜色填充图形

时间:2018-05-18 22:15:31

标签: vba

我想在我的图表上格式化系列,我注册了宏:

ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With

然后我把它放到我的代码中:

        With Wykres
            .ShowLegendFieldButtons = False
            .ShowValueFieldButtons = False
            .ShowAxisFieldButtons = False
            .ShowAllFieldButtons = False
            .Legend.Delete
            .ChartStyle = 340
            .SetElement (msoElementChartTitleAboveChart)
            .ChartTitle.Text = "Ilość w podziale na województwa"
            .SetElement (msoElementDataLabelOutSideEnd)
            .Parent.RoundedCorners = True
            .ChartArea.Format.Line.ForeColor.RGB = KolorUzytkownika
            .FullSeriesCollection.Format.Fill.ForeColor.RGB = KolorUzytkownika
        End With

但我的代码的最后一行出了问题。我收到了消息:"对象不支持此属性或方法"。我使用后期绑定,但我想这并不重要。

2 个答案:

答案 0 :(得分:6)

Collection的类型为Series。您无法为Collection类型访问/修改.FullSeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)类型的媒体资源。因此错误。

enter image description here

您需要先从集合中访问该项目,然后才能访问该项目类型的所有公共属性和方法。

async function getNumPages(substr) => { const result = await makeRequest(substr); return result; }

答案 1 :(得分:1)

这将循环并格式化第一个ChartObject上属于第一个Worksheet的图表上的所有系列。在您的情况下,请将Worksheets(1).ChartObjects(1).Chart替换为Wykres

Sub formatChartSeries()

    Dim s

    For Each s In Worksheets(1).ChartObjects(1).Chart.SeriesCollection
        s.Format.Fill.ForeColor.RGB = RGB(146, 208, 80) 'format fill / marker
        s.Format.Line.ForeColor.RGB = RGB(146, 208, 80) 'format border / line
    Next s

End Sub

以上解决方案与Excel 2010兼容,后者不支持FullSeriesCollection

相关问题