Search code examples
excelvbaformattingshapes

Change the Color of shape and 3D formatting


I want different color formatting, using msoShapeStylePreset to apply color using RGB.

When I tried to apply the color using RGB, it filled the shape with two colors, which is not what I intended.

The goal is that when any shape is selected, its color should change, while the rest of the shapes remain the same.
I also want the option to choose the color combination for both.
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

I want to change the color like this:
enter image description here


Solution

  • Assign macro for each shape

    • Right click on a shape > Assign Macro, select ShpClick, click OK
    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