Link to home
Start Free TrialLog in
Avatar of Cook09
Cook09Flag for United States of America

asked on

Why doesn't "i" Work with Pictures

I have a worksheet that has several "Pictures" or, Picture objects, on it that I would like to remove.

In running the Macro Recorder, it lists these objects as ActiveSheet.Shapes("Picture #") or
ActiveSheet.Shapes("Picture 1").Select

Open in new window

In putting together some code to delete these I used - This is the short version to my question:

Sub DeleteShapes()
Dim shp As Shape, i As integer
i = 1
   For Each shp In ActiveSheet.Shapes
     ActiveSheet.Shapes("Picture [b]i[/b]").Delete
    i = i + 1
   Next
i = 0
End Sub

Open in new window


That doesn't work though, it doesn't recognize the "i".  However, If I replace the i with a 1, then it will work.  I have tried changing i to Long, String, etc. Even though i = 1 is the right value, the code won't allow it to excecute, it has to be the actual number.  Why is this?  It defeats the whole purpose for variables.
ASKER CERTIFIED SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cook09

ASKER

Thanks, your result worked better than what I had put together, but there was one oddity.  When I tried to run your code initially, I got an error that "Cannot Enter into Break Mode at this Time."  When I added the On Error Resume Next, then it worked fine.  That was the first time I've seen that error, have you seen it before?
Avatar of Cook09

ASKER

I think I may have figured out the error, there are some Merged Cells and it may have errored out on those.  That's the thought anyway.