0

I am simply trying to create a rectangle shape in a specific worksheet, formatting it & assign a macro to it using VBA.

Here goes my attempt :

Set t = wsJTO.Range("H" & 5 & ":G" & 6)    
Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ShapeRange.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"

According to the debugger, there is an error with the third line & I don't seem to understand what's wrong with it. Help would be appreciated

1 Answer 1

2

Silly me ... All I had to do was get rid of "ShapeRange" since it doesn't have a fill property. The following code does the job if it might serve someone in the future :

Set t = wsJTO.Range("H" & 5 & ":G" & 6)

Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.