PDA

View Full Version : [SOLVED] Problem with ActiveSheet.Shapes



Cyberdude
09-24-2005, 10:47 AM
When I combine two statements into one, it doesn't work. What's the problem here: :banghead:

Sub TestPhfft()
'The next 2 lines work OK
ActiveSheet.Shapes("Rectangle 3").Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 3
'The next line gets a Runtime Error 438:
' "Object doesn't support this property or method"
ActiveSheet.Shapes("Rectangle 3").ShapeRange.Fill.ForeColor.SchemeColor = 3
End Sub

malik641
09-24-2005, 10:54 AM
This works:




Sub TestPhfft()
ActiveSheet.Shapes("Rectangle 3").Fill.ForeColor.SchemeColor = 3
End Sub

All I did was get rid of the ShapeRange....Don't ask me why/how it works, I just took a lucky guess :)

TonyJollans
09-24-2005, 11:00 AM
In the first piece of code you are expanding the shape out to the selection and, to focus back in on the shape in the second statement, must use the selection's shaperange. When combining the two statements you are not selecting, and already have a reference to the shape, so can go directly to the fill - as shown by Joseph.

Cyberdude
09-24-2005, 11:10 AM
Tony, I think you've got it. I had a feeling it was something like that ... just don't have the smarts to know what it was exactly. Thanks!
And thanks to Joseph for figuring out what to do.