Vba - Set transparent color or direct hex value of label backcolor?

Kenny Bones picture Kenny Bones · Sep 3, 2010 · Viewed 8.9k times · Source

I want to insert a label into a PowerPoint presentation. But I don't want any background on there, or, have the background color be the same as the what is underneath.

I've found that 082F68 is the hex code I want. The RGB code is: 8, 47, 104 This color is supposed to be bluish, but when I insert it, it just gets brown. I really don't want that. I also tried setting label.backcolor to Color.Transparent. But that isn't recognized. Neither is System.Drawing.Color.Transparent either. It just says it needs an object reference.

But really, isn't it possible to use direct hex values for label backgrounds?

Answer

Matthew Kraus picture Matthew Kraus · Jun 4, 2013

(super late response, but in case others have this issue)

This will create a label on slide 1 in the upper-left hand corner. On my system, I get the bluish background color you are talking about.

ActivePresentation.Slides(1).Shapes.AddLabel(Orientation:=msoTextOrientationHorizontal, _
    Left:=0, Top:=0, Width:=50, Height:=50).name = "TestLabel"

Dim sh As Shape
Set sh = ActivePresentation.Slides(1).Shapes("TestLabel")
sh.TextFrame.TextRange.Text = "Hello"        
sh.Fill.BackColor.RGB = RGB(8, 47, 104)

You can also set the fill transparency to 100% (fill will be see-through):

sh.Fill.Transparency = 1#

I'm not sure what you're using as a "placeholder", but any Shape object will have an ID:

MsgBox "Label ID = " + CStr(sh.Id)

but it is probably easier to refer to it by name as I do above. The ID is a numerical value and isn't the same as the shape index, making it harder to reference the shape by its ID.

Above I programmatically assign the name, but you can also name the shape yourself: Home -> Arrange -> Selection Pane. In the selection pane you can click on the names of all the shapes on the slide to edit them. You can now refer to these shape names in code.