title: changing slice colour of a pie chart in excel VBA
body: <p>Initially I wrote a function which changes the appearance of a series of pie-charts according to predefined colour themes </p>
  
  <pre><code>    Function GetColorScheme(i As Long) As String
  Const thmColor1 As String = "C:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\Blue Green.xml"
  Const thmColor2 As String = "C:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\Orange Red.xml"
      Select Case i Mod 2
          Case 0
              GetColorScheme = thmColor1
          Case 1
              GetColorScheme = thmColor2
      End Select
  End Function
  </code></pre>
  
  <p>However, the paths are not constant and I would like to define each Pie chart slice on its own by an rgb colour. 
  I found here on stackoverflow in a previosu topic (<a href="https://stackoverflow.com/questions/17385213/how-to-use-vba-to-colour-pie-chart">How to use VBA to colour pie chart</a>)  a way to change the colour of each slice of a pie chart</p>
  
  <p>but I don't knwo how to implement the code into the function mentioned above. Could I potentially write</p>
  
  <pre><code>    Function GetColorScheme(i As Long) As String
  
      Select Case i Mod 2
          Case 0
              Dim clr As Long, x As Long
  
  For x = 1 To 3
      clr = RGB(0, x * 8, 0)
      With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(x)
          .Format.Fill.ForeColor.RGB = clr
      End With
  Next x
          Case 1
              Dim clr As Long, x As Long
  
  For x = 1 To 3
      clr = RGB(0, x * 8, 0)
      With ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1).Points(x)
          .Format.Fill.ForeColor.RGB = clr
      End With
  Next x
      End Select
  End Function
  </code></pre>
  
  <p>The function is linked to the main part of the script (which is) </p>
  
  <pre><code>For Each rngRow In Range("PieChartValues").Rows
  chtMarker.SeriesCollection(1).Values = rngRow
  ThisWorkbook.Theme.ThemeColorScheme.Load GetColorScheme(thmColor)
  chtMarker.Parent.CopyPicture xlScreen, xlPicture
  lngPointIndex = lngPointIndex + 1
  chtMain.SeriesCollection(1).Points(lngPointIndex).Paste
  thmColor = thmColor + 1
  </code></pre>
  
  <p>where the line </p>
  
  <pre><code> ThisWorkbook.Theme.ThemeColorScheme.Load GetColorScheme(thmColor) 
  </code></pre>
  
  <p>gets the value of the function  (see first bit of code - the original function) but now I don#t longer have the thmColor variable defined and don't knwo how to best implement the code into the function part</p>