title: VBA: Extracting the RGB value of lines in a chart with default colors
body: <h2>Problem</h2>
  
  <p>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 values (rather than updating them as the theme is changed, series are reordered, etc.)</p>
  
  <h2>Usecase</h2>
  
  <p>My actual usecase is that I would like to make the datalabels match the color of the lines/markers in a line chart. This is easy if I have explicitly set the colors of the series via a scheme or explicit RGB values, e.g.</p>
  
  <pre><code>' assuming ColorFormat.Type = msoColorTypeRGB
  s.DataLabels.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB= _
  s.Format.Line.ForeColor.RGB
  </code></pre>
  
  <p>However, doing this when the series color is assigned automatically results in white labels. More specifically, both of the following equalities hold</p>
  
  <pre><code>s.Format.Line.ForeColor.Type = msoColorTypeRGB 
  s.Format.Line.ForeColor.RGB = RGB(255,255,255)  ' White
  </code></pre>
  
  <p>And yet the line of course isn't white, but is an automatically assigned color from the theme. This shows that the color is automatically assigned</p>
  
  <pre><code>s.Border.ColorIndex = xlColorIndexAutomatic
  </code></pre>
  
  <p>I suppose it makes sense that the color isn't stored with the series in question. Even storing the index into the color scheme wouldn't generally work as Excel needs to change the color if another data series is added or someone reorders the data. Still, I would love it if there were some way to identify the current RGB value automatically. </p>
  
  <h2>An Ugly Workaround</h2>
  
  <p>For charts with 6 or fewer entries, a simple workaround is to exploit the fact that theme colors are assigned sequentially, so I can do (e.g.)</p>
  
  <pre><code>chrt.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange.Font.Fill.ForeColor.ObjectThemeColor _
  = msoThemeColorAccent1
  </code></pre>
  
  <p>Presumably this could be extended to account for the <code>TintAndShade</code> used to differentiate entries once the theme has been exhausted, but this is such an ugly hack.</p>
  
  <h2>Research</h2>
  
  <p>Someone asked essentially the same question (how to extract theme colors) <a href="https://stackoverflow.com/questions/19395760/">here</a>, but it was never answered. There are several sources suggesting ways to convert a known theme color into RGB values (e.g. <a href="https://stackoverflow.com/questions/21142732">here</a> and <a href="http://www.wordarticles.com/Articles/Colours/2007.php" rel="nofollow noreferrer">here</a>) but that just begs the question; I don't know the color <em>a priori</em>, other than "whatever color this line currently is."</p>