eirikdaude
eirikdaude

Reputation: 3254

Out of bounds error on for each sh in ws.Shapes statement

I have the following sub which is supposed to loop through all the shapes in a sheet and do something:

Private Sub plasser_knappar(ws As Worksheet)
    Dim sh As Shape

    For Each sh In ws.Shapes
        Debug.Print "Do stuff"
    Next sh
End Sub

However, on one of my sheets I get an error when the code reaches the line For Each sh in ws.Shapes - "Run-time error '-2147352567 (80020009) The index into the specified collection is out of bounds". This error does not happen in other worksheets in the workbook. Can anyone shed some light on what might be the problem here?

Upvotes: 1

Views: 653

Answers (1)

FunThomas
FunThomas

Reputation: 29296

There is a discussion on MSDN about this error code and it seems that this was caused by an corrupt workbook.

Upvotes: 1

Related Questions