【问题标题】:Set the chart colors to automatic in Excel VBA在 Excel VBA 中将图表颜色设置为自动
【发布时间】:2012-09-03 16:35:10
【问题描述】:

我有一个宏将堆叠条形图上的所有系列设置为具有相同的颜色,以及像这样的其他几个位:

Sub RefreshLabels()

    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

    Dim ch As Chart
    ActiveSheet.ChartObjects("ProjectChart").Activate
    Set ch = ActiveChart
    ch.SetElement (msoElementDataLabelCenter)

    Dim sc As SeriesCollection
    Set sc = ch.SeriesCollection

    Dim showLabel As Boolean
    If (Range("showLabels").Value = "Y") Then
        showLabel = True
    Else
        showLabel = False
    End If

    Dim sameColor As Boolean
    If (Range("sameColor").Value = "Y") Then
        sameColor = True
    Else
        sameColor = False

    End If

    Dim s As Series
    For Each s In sc

        If (sameColor = True) Then
            s.Border.Color = RGB(Range("rgb_r"), Range("rgb_g"), Range("rgb_b"))
            s.Interior.Color = RGB(Range("rgb_r"), Range("rgb_g"), Range("rgb_b"))
        Else
            'CODE HERE TO MAKE COLORS AUTOMATICALLY SELECTED FROM PALLETTE
        End If

        Set dl = s.DataLabels
        dl.ShowSeriesName = showLabel
        dl.ShowValue = False


    Next


End Sub

但是我需要将系列更改回默认堆叠条形图的选项,并自动将颜色选择为各种调色板。

如果您需要任何进一步的信息,请告诉我。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    好的,解决了这个问题。您可以在图表上调用一种方法来重置样式:

    ActiveChart.ClearToMatchStyle
    

    希望对某人有所帮助!

    【讨论】:

    • 非常酷。您应该接受自己的回答作为答案。
    猜你喜欢
    • 2013-12-04
    • 2020-02-26
    • 2013-05-19
    • 2013-10-06
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2017-04-19
    相关资源
    最近更新 更多