excel vba - Can't assign to read-only property vba -
getting "compile error: can't assign read-only property" following:
with wsdata.shapes("rectangle 1").fill .pattern = xlgrid .forecolor.rgb = rgb(255, 0, 0) end
you missing shaperange property in middle:
with wsdata.shapes("rectangle 1").shaperange full code:
with wsdata.shapes("rectangle 1").shaperange .fill .pattern = xlgrid .backcolor.rgb = rgb(255, 0, 0) end end edit 1: code possible error handling
option explicit sub colorchape() dim wsdata worksheet dim myshp shape set wsdata = worksheets("sheet1") ' <-- modify sheet's name on error resume next set myshp = wsdata.shapes("rectangle 1") on error goto 0 if myshp nothing ' <-- unable set shape, doesn't exist in specified sheet msgbox "`rectangle 1` shape doesn't exist in " & wsdata.name & " sheet!", vbcritical else myshp .fill .backcolor.rgb = rgb(255, 0, 0) ' rest of code goes here end end end if end sub
Comments
Post a Comment