views:

161

answers:

1

Hi all, I have a method in my macro that executes the following code:

Set myDocument = Worksheets("sheet1")
For each sh in myDocument.Shapes
    If sh.Name = "square" Then
        sh.Cut
    End If
Next

My problem is that the code causes an error on the line sh.Cut. I know that there is a shape called "square" - I can see (visually) the shape in the document, but Excel just doesn't want to cut that shape out. Any suggestions as to why this might be?


EDIT: To clarify, this behaviour does not always happen. Usually it is alright - it only seems to happen sometimes, but I can't see any co-relation between the times that it happens.

Thanks.

+2  A: 

There's only two reasons to ever use the Select method. 1) You want to select something. 2) You're working with shapes and getting weird errors. It doesn't make sense, but try

sh.Select
sh.Cut

and I'll bet it will work every time.

Dick Kusleika