How to Process For Each...Next Loop in a Specific Shape Order?

S

sbmack7

I want to process a collection of shapes in a specific order through a
For Each...Next loop. But the current order sequence is not the same
as my desired ordering. It looks like shapes are processed based on
the order in which they were placed on the page. I suppose I could
add a custom property that contains an ordering number to reach shape
and then use an indexed For... Next construct to process them.

Is there a better way to do it?

Thanks,

SteveM
 
J

JuneTheSecond

How would you like Shape.ID and Shapes.ItemfromID?
For example,
Sub test()
Dim I As Integer
Dim N As Integer
Dim myCollection As New Collection
N = ActivePage.Shapes.Count
For I = 1 To N
myCollection.Add ActivePage.Shapes.ItemFromID(I)
Next

Dim shp As Visio.Shape

For Each shp In myCollection
Debug.Print shp.Index, shp.Name
Next
End Sub
 
S

sbmack7

How would you like Shape.ID and Shapes.ItemfromID?
For example,
Sub test()
Dim I As Integer
Dim N As Integer
Dim myCollection As New Collection
N = ActivePage.Shapes.Count
For I = 1 To N
myCollection.Add ActivePage.Shapes.ItemFromID(I)
Next

Dim shp As Visio.Shape

For Each shp In myCollection
Debug.Print shp.Index, shp.Name
Next
End Sub

J2,

Thanks for the response. I see what you are trying to do and that is
aligned with my workaround. The myCollection.Add line in your code
fails. I have not used the Collection object before, so can not
pinpoint the error.

Anyway, I appreciate your effort to respond.

SteveM
 

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

Top