Reputation: 2607
This is more of a conceptual question than a code issue. When coloring shapes with VBA, I've always used the ForeColor
property as a force of habit, but now I am curious as to how BackColor
functions. The documentation really doesn't provide much specificity as to the distinction. The only pertinent information I can see there is:
If you set the BackColor property on a Form object or a PictureBox control, all text and graphics, including the persistent graphics, are erased. Setting the ForeColor property doesn't affect graphics or print output already drawn.
which really doesn't seem to adequately explain the difference between them.
I did a bit of experimentation with setting the Back and Fore colors of shapes in different orders in the code and different text and other items contained, but I cannot for the life of me find any sort of consistent difference. Frankly, it seems like the BackColor
property is entirely useless, since ForeColor
has seemed to just write over whatever color there is.
Does anyone know a good way to explain the difference between them (or a source of better documentation where I can read up on the differences)?
Upvotes: 6
Views: 5420
Reputation: 2979
BackColour is used when you apply the TwoColorGradient method.
For example, if you select a shape in PowerPoint and type this:
?ActiveWindow.Selection.ShapeRange(1).Fill.BackColor
You'll probably see 16777215 (white) returned and if you change it to red, you'll see no change:
ActiveWindow.Selection.ShapeRange(1).Fill.BackColor.RGB = RGB(255,0,0)
But if you apply the gradient method:
ActiveWindow.Selection.ShapeRange(1).Fill.TwoColorGradient _
msoGradientDiagonalUp, 1
And then change the BackColor, you'll see a change.
Upvotes: 4