Get the Tab color in Excel 2007 in C#
Posted on 2012-04-12
I found out how to set a tab's color using c# in Excel 2007:
LastSheet.Tab.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.ForestGreen);
This does indeed set the tab color to ForestGreen (although as a side note, I would like to be able to set it based on RGB or ARGB).
However, now what I want to do is retrieve the current(initial) color of the tab into a variable. I tried this:
currentColor = (System.Drawing.Color)LastSheet.Tab.Color;
Although the compiler was happy with this, at runtime I got an error:
"Specified cast is not valid."
I suspect I need to use the ColorTranslator method somehow, but I tried some different configurations and none worked.