Skip to content

Instantly share code, notes, and snippets.

@ncalm
Last active August 23, 2024 23:59
Show Gist options
  • Save ncalm/482b8c9a335b2234f882639a4253db3a to your computer and use it in GitHub Desktop.
Save ncalm/482b8c9a335b2234f882639a4253db3a to your computer and use it in GitHub Desktop.
Sub GetThemeColorsForPythonPalette()
Dim i As Integer
Dim colorHex As String
Dim pythonCode As String
Dim colorsArray() As String
Dim themeColor As Long
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name = "Theme Colors" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
Exit For
End If
Next ws
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "Theme Colors"
ReDim colorsArray(1 To 10)
For i = 1 To 10
themeColor = ThisWorkbook.Theme.ThemeColorScheme(i).RGB
colorHex = Right("000000" & Hex(themeColor), 6)
colorsArray(i) = "'#" & colorHex & "'"
Next i
pythonCode = "from cycler import cycler" & vbCrLf & _
"custom_palette = [" & Join(colorsArray, ", ") & "]" & vbCrLf & _
"custom_cycle = cycler('color', custom_palette)"
ws.Cells(1, 1).Formula2 = "=PY(""" & pythonCode & """,1)"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment