Keyser Soze
Keyser Soze

Reputation: 272

Formatting a Shape (Command button) using VBA

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

Upvotes: 0

Views: 260

Answers (1)

Keyser Soze
Keyser Soze

Reputation: 272

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"

Upvotes: 2

Related Questions