Vba - 设置标签背景色的透明颜色或直接十六进制值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3635938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Vba - Set transparent color or direct hex value of label backcolor?
提问by Kenny Bones
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.
我想在 PowerPoint 演示文稿中插入一个标签。但我不希望那里有任何背景,或者,背景颜色与下面的颜色相同。
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.
我发现 082F68 是我想要的十六进制代码。RGB 代码是:8, 47, 104 这种颜色应该是蓝色的,但是当我插入它时,它变成了棕色。我真的不想那样。我也尝试将 label.backcolor 设置为 Color.Transparent。但这是不被认可的。System.Drawing.Color.Transparent 也不是。它只是说它需要一个对象引用。
But really, isn't it possible to use direct hex values for label backgrounds?
但实际上,是否可以将直接十六进制值用于标签背景?
回答by Matthew Kraus
(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.
这将在左上角的幻灯片 1 上创建一个标签。在我的系统上,我得到了你所说的蓝色背景颜色。
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):
您还可以将填充透明度设置为 100%(填充将是透明的):
sh.Fill.Transparency = 1#
I'm not sure what you're using as a "placeholder", but any Shapeobject will have an ID:
我不确定您使用什么作为“占位符”,但任何Shape对象都有一个 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.
但是像我上面所做的那样按名称引用它可能更容易。ID 是一个数值,与形状索引不同,因此更难通过其 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.
上面我以编程方式分配名称,但您也可以自己命名形状:主页 -> 排列 -> 选择窗格。在选择窗格中,您可以单击幻灯片上所有形状的名称进行编辑。您现在可以在代码中引用这些形状名称。
回答by Tom
Try *.BackgroundColor = -1 'Transparent
试试 *.BackgroundColor = -1 '透明