Hi.
This has been around for a long time. I posted a long time ago on Oberon Place but it's still there.
This causes crash in all versions.It's still here in X6.
Sub test() Dim s As Shape, sr As New ShapeRange sr.Add sEnd Sub
Yes I know s should not be nothing but sometimes when testing code you might lose your object or it doesn't even get set for reason of other errors from either program glitches or user coding error. This will cause unnecessary program crashes when one is testing/debugging code. Please fix so it doesn't crash.
It's more stable similar function AddRange can take anything without causing the program to crash.
~John
Caused me some headaches too, so I do things like this...
If Not s Is Nothing then sr.Add s
...or more often than not I send it to an error handler to help with debugging or a prevent a crash.
Steve said:If Not s Is Nothing then sr.Add s
In cases where I had to loop through a dynamic ShapeRange, even "Not s Is Nothing" didn't work for me. When I had Shapes deleted from a ShapeRange during runtime, the Locals window in the VBA editor was constantly saying "The referenced Shape doesn't exist anymore", so I used
If Not s Is Empty Then ...
I assume a shape is passed by reference in a ShapeRange, so it was better to check if the referenced object (the deleted Shape) is empty rather than nothing, cause the reference pointer was still there, but no object to fill it. Maybe this can help anyone in the future.