VBA: Extracting the RGB value of lines in a chart with default colors

前端 未结 3 1858
抹茶落季
抹茶落季 2021-02-08 11:09

Problem

I would like to know how to read the current RGB value of an automatically assigned color in a chart, even if this entails freezing the colors to their current

3条回答
  •  爱一瞬间的悲伤
    2021-02-08 12:09

    After half a day I managed to solve this issue:

           Sub ......()
    
           Dim k as Integer
           Dim colorOfLine as Long
    
           ...............
           .................
    
           'Loop through each series
           For k = 1 To ActiveChart.SeriesCollection.Count
    
                With ActiveChart.FullSeriesCollection(k)
    
                    .HasDataLabels = True
    
                    'Put a fill on datalabels
                    .DataLabels.Format.Fill.Solid
    
                    'Get color of line of series
                    colorOfLine = .Format.Line.ForeColor.RGB
    
                    'Assign same color on Fill of datalabels of series
                   .DataLabels.Format.Fill.ForeColor.RGB = colorOfLine
    
                   'white fonts in datalabels
                   .DataLabels.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
    
                End With
    
            Next k
            ..........
            End Sub
    

提交回复
热议问题