I have done VBA for making line chart with chart having more than 20 series. I want to give colors to the lines using msoThemeColorAccent1, msoThemeColorAccent2, msoThemeColorAccent3 etc.. all the way to msoThemeColorAccent6. But using numbers 1 to 6, I am able to give only six colors of chosen color palette, but I also want to use colors of other palette without manually choosing them.
If I chose 2nd palette manually, the numbers 1 to 6 start referring to other palette.
I think there is some concept of ThemeColorScheme but not sure how to use the same.
Any guidance would be helpful.
Thanks
Note: The following is True for all kind of Excel objects, like cells, shapes, chart-series...
When you use a palette, the idea is to store a kind of index into the palette. There are basically 10 colors in a palette (there are some more, but let's keep it simple), those are the colors (from left to right) that you can see in the color picker. The index values are 1-10, and you can access them with
When you look at the color picker, you see that there are many lighter and darker variations of a color. When you select a color, two properties are written:
ThemeColorandTintAndShade. The latter defines how dark or light a color is used.Now (as you already wrote), when you change the colors of your document by choosing a different Theme (or only the colors of the Theme), the objects of your Excel will change to the new palette. This is because you said (for example) use
xlThemeColorAccent1(the 5th color of your palette), and now the 5th color is a new, different color. As long as you useThemeColor, there is no way around that.But there is an alternative: When you open the color picker in Excel and choose "More Colors", you can pick any color you want. This is done by writing the
Color-property. TheColor-property saves the RGB-Value of a color (as a Long Integer). When you use theColor-property, Excel will "forget" the ThemeColor-Index (set it to 0). Once you define a color that way, changing the palette will not change the color of the object (because the ThemeColor-Index is 0 and the color is read from theColor-property).So what you have to do is to define the Colors you need and figure out the RGB-value. The following small routine can help you. It will write the color value of a cell into that cell.
Open a blank sheet and set the color for as many cells you want (using the Theme colors or individual colors). Select the colored cells and call the macro.
The handy thing is that if you format a cell using
ThemeColor, Excel automatically sets theColor-property, so with this method you get the color values of all cells, no matter how they where colored. By writing theColor-value to itself, theThemeColor-index is "forgotten". You can now even change the Theme, all colors remain (so you can format some more cells, rerun the macro and get the colors of the new Theme).Now you need to copy the color values into your code and use them:
(Note that for Series, the property name for
ColorisRGBand forThemeColorit isObjectThemeColor)