尝试更改形状的颜色和 3D 格式

Trying to Change the Color of shape and 3D formatting

提问人:HSHO 提问时间:11/10/2023 最后编辑:FunThomasHSHO 更新时间:11/11/2023 访问量:48

问:

我一直在尝试使用不同的颜色格式,但我在使用 时遇到了问题,它允许我使用 RGB 应用颜色。msoShapeStylePreset

当我尝试使用 RGB 应用颜色时,它用两种颜色填充了形状,这不是我的意图。我可能在写它的方式上做错了什么。

我需要你的帮助来解决这个问题。目标是,当选择任何形状时,其颜色应该不同,而其余形状应该保持不变。我还想要为两者选择颜色组合的选项。

enter image description here

Sub Select1()
    
    Sheet1.Shapes("Group 1").ShapeStyle = msoShapeStylePreset41
    Sheet1.Shapes("Shape1").ShapeStyle = msoShapeStylePreset27
    
    With Sheet1.Shapes("Shape1").ThreeD
        .BevelTopType = msoBevelCircle
        .BevelTopInset = 6
        .BevelTopDepth = 6
    End With
End Sub

Sub Select2()
    Sheet1.Shapes("Group 1").ShapeStyle = msoShapeStylePreset41
    Sheet1.Shapes("Shape2").ShapeStyle = msoShapeStylePreset27
    With Sheet1.Shapes("Shape2").ThreeD
        .BevelTopType = msoBevelCircle
        .BevelTopInset = 6
        .BevelTopDepth = 6
    End With
End Sub

我想像这样改变颜色

enter image description here

Excel VBA 格式 设置形状

评论


答:

1赞 taller 11/11/2023 #1

为每个形状分配宏

  • 右键单击形状 > ,选择 ,单击Assign MacroShpClickOK
Sub ShpClick()
    Dim HLColor As Long
    Dim sCaller As String
    HLColor = RGB(0, 255, 0) ' modify as needed
    sCaller = Application.Caller
    Sheet1.Shapes("Group 1").ShapeStyle = msoShapeStylePreset9
    With Sheet1.Shapes(sCaller).Fill
        .Visible = msoTrue
        .ForeColor.RGB = HLColor
        .Transparency = 0
        .Solid
    End With
    With Sheet1.Shapes(sCaller).ThreeD
        .BevelTopType = msoBevelCircle
        .BevelTopInset = 6
        .BevelTopDepth = 6
    End With
End Sub

enter image description here