Ok, I must be losing memory or something, but what is the correct way to loop through a ShapeRange that changes over time? As an example I have something like this (in pseudocode):
Tag:For Each S In SR.Shapes.All For Each T In SR.Shapes.All If S compared to T is something Then T.Delete Goto Tag End If Next T Next S
Tag:For Each S In SR.Shapes.All
For Each T In SR.Shapes.All
If S compared to T is something Then
T.Delete Goto Tag
End If
Next T
Next S
And no matter what I try:
it throws an error at some point that the shapes are no longer there. Basically what I want to do here is remove overlapping shapes in the same ShapeRange with specific parameters.
Any suggestions?
no need to use SR.Shapes.All or SR.Shapes (For Each s In sr)to check if shape exists in the document you can set error handling (On Error Goto ...) and try to move it (s.Move 0.0)try to use less Goto, use Exit For insteadyou can also use loops with counters, for example:
For z = 1 To sr.Count - 1 For i = z + 1 To sr.Count 'use next shape and all subsequent ones If sr(z) =compare= sr(i) then Exit For 'goto after Next i Next iNext z
Thanks for the comment. I will try to merge elements from both replies. Also, this should help with some other functions I have been making.