Excel Crash on Mouse-Over of Object


November 14, 2001 - by

Bill writes:

I have a document that has become very unstable. Every time that my mouse gets near one of the red comment triangles, Excel will crash.

After looking at Bill's worksheet, I found a somewhat innocuous macro that was causing the problem. In an effort to clear out some pictures and command buttons on the sheet, Bill had the following code:

For Each sh in ActiveSheet.Shapes
    sh.Delete
Next sh

I set up a new test workbook and was able to duplicate the problem. Apparently, the yellow box that pops up when you hover over a cell's red comment indicator is a Shape. I ran the above code, this time asking for a MsgBox sh.Name. Sure enough, included on among the pictures and buttons were one shape for each comment. Deleting this shape left the worksheet in a corrupt condition.

The workaround for this book was to remove the sheet and insert a new one without the broken comments. I also suggested changing the macro to this:

If Not Left(sh.Name, 7) = "Comment" Then sh.Delete