GG24
GG24

Reputation: 313

How to iterate through some shapes in visio?

I'd like to iterate through some shapes in Visio, I have a solution that works but which is a bit low because there are a lot of shapes (a thousand maybe and I'm only interested to iterate on twenty or thirty of them) :

Dim shp As Visio.Shape
Dim pagShape As Visio.Shape
Set pagShape = Visio.ActivePage.PageSheet
For Each shp In Visio.ActivePage.Shapes

If InStr(shp.Data3, "_tag") Then
If StrComp(Replace(shp.Data3, "_tag", ""), name) = 0 Then
    shp.text = name
Else:
    shp.text = ""
End If
End If
Next shp

Is it possible to add some shapes in a kind of list instead of selecting all existing shapes ? something like that :

For Each shp In List 

thank you very much in advance :)

edit : I have done it that way :

the declaration and set part :

Public Collection_shp As Collection
Set Collection_shp = New Collection

When I create a label shape I add it to the collection :

Collection_shp.Add Item:=vso_sg

And the part with the loop :

Dim shp As Visio.Shape
For Each shp In Collection_shp 

If InStr(shp.Data3, "_tag") > 0 Then
If StrComp(Replace(shp.Data3, "_tag", ""), name) = 0 Then
    shp.text = name
    Else
    shp.text = ""
    End If
    End If
    Next shp

Upvotes: 0

Views: 1380

Answers (1)

GG24
GG24

Reputation: 313

I have done it that way :

the declaration and set part :

Public Collection_shp As Collection
Set Collection_shp = New Collection

When I create a label shape I add it to the collection :

Collection_shp.Add Item:=vso_sg

And the part with the loop :

Dim shp As Visio.Shape
For Each shp In Collection_shp 

If InStr(shp.Data3, "_tag") > 0 Then
If StrComp(Replace(shp.Data3, "_tag", ""), name) = 0 Then
    shp.text = name
    Else
    shp.text = ""
    End If
    End If
    Next shp

Upvotes: 0

Related Questions