Skip to main content

PowerPoint 2013 - Setting colors programmatically (VSTO)

Submitted by admin on Sat, 10/22/2016 - 22:59

Just setting myShape.Fill.ForeColor.RGB = Color.Red.ToArgb() would be nice.. but it doesn't work as you would expect. What will happen is you get the color blue instead of red.

PowerPoint 2013 (and I assume 2007) use a different color format, BGR. So you either have to shift bits manually, or much easier, you use ColorTranslator.ToOle(). This is extremely confusing, considering that the property is called RGB.

So, to give you a working example:

myShape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(Color.Red);

There is also ColorTranslator.FromOle(), which is going to to convert the BGR integer back to a Color object.

I also found some incorrect solutions out there on the internet that do the bit shifting manually, which seem to forget the alpha value, just be aware of that.