find a shape without looping through all of them ?

M

mikeFin

Hello!

On every CodeSnippet I can find, I always see that you have to loop through
all shapes to find the one shape you want to work with.

So my question here is: Is there a way to work with a shape (of whom I do
know the Name or ID) without having to loop through all shapes?

I used to do something like this:

For Each shp In ActivePage.Shapes
If shp.Name = "myShapeName" Then
...
End If
Next

Is there a quicker way to do that?

Thanks in advance!
 
A

AlEdlund

try something like this

Dim visShape As Visio.Shape
Set visShape = Application.ActivePage.Shapes(strShapeName)

of course if the shape doesn't exist you're going to get an error

al
 
P

Paul Herber

Hello!

On every CodeSnippet I can find, I always see that you have to loop through
all shapes to find the one shape you want to work with.

So my question here is: Is there a way to work with a shape (of whom I do
know the Name or ID) without having to loop through all shapes?

If you have the shapeID then you can access the shape directly in the
shapes collection:

shp = ... Shapes[shapeID]
 

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