Window Error when deleting shapes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i am suing excel 2000 vba and win 2000 platform
I use the following code to delete all shapes in a worksheet

Do While Book.Worksheets(nameofsheet).Shapes.Count >
Book.Worksheets(nameofsheet).Shapes(Book.Worksheets(nameofsheet).Shapes.Count).Delete
Loop

Sometimes the excel tell that a windows error and the process is terminated
during the middle. I do the similar operation with other sheets, there is no
error.
Somtimes the process can run successfully. The error is by chance.

I have tried to use a more powerful machine with same platform to test it.
It stilll have such error by chance.

What can i do to avoid the error, or how can this delete shape method be
improved?

Thank you!
 
It is usually best to make the sheet with the shapes the active sheet
when doing anything with shapes.
I've seen the same problem you describe and I believe the cause
lies with a shape index number being outside of the count range.
Here is an alternative you can try...

Sub RemoveAllShapes()
Worksheets("Sheet4").Select
Worksheets("Sheet4").Shapes.SelectAll
Selection.ShapeRange.Delete
End Sub

Jim Cone
San Francisco, USA



i am suing excel 2000 vba and win 2000 platform
I use the following code to delete all shapes in a worksheet

Do While Book.Worksheets(nameofsheet).Shapes.Count > 0
Book.Worksheets(nameofsheet).Shapes(Book.Worksheets(nameofsheet).Shapes.Count).Delete
Loop

Sometimes the excel tell that a windows error and the process is terminated
during the middle. I do the similar operation with other sheets, there is no
error.
Somtimes the process can run successfully. The error is by chance.

I have tried to use a more powerful machine with same platform to test it.
It stilll have such error by chance.

What can i do to avoid the error, or how can this delete shape method be
improved?

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Select shape leading to Out of memory 4
Loop to delete shapes 8
Excel to powerpoint 1
Need Help Setting Cell Values 1
Programming Shapes 3
shape remains selected 1
Delete some textboxes with tag,VBA 1
Late Binding 4

Back
Top