How to check for shape's existence on page?

S

sdart

I'm brand new to visio, but have a programming background. I'm lacking the
syntax knowledge to do the following, but I know there's got to be a way to
do it.

I can pull text content out of a shape, but I need to make sure the shape
actually exists on the page, otherwise the macro chokes. I want something
like this:

If ShapeExists("MyShapeName") then
do something
end if

What the correct syntax in visio? TIA
 
J

John Goldsmith

There are various ways of identifying shapes, either by name or ID, but
here's a method that checks the shape's universal name property:

Sub FindMyShapes()
Dim shp As Shape

For Each shp In ActivePage.Shapes
If shp.NameU = "My Shape Name" Then
'Do something
End If
Next shp

End Sub

Bear in mind if your Do something action is to delete the respective shape
you'll want to create an indexed loop that runs backwards (ie For i =
ActivePage.Shapes.Count To 1 Step -1).

You could also check for a shape based on a particular Master with the
following:

If shp.Master.NameU = "My Shape Master Name" Then...

Finally you might find this link on shape objects handy:

http://msdn2.microsoft.com/en-us/library/aa201761(office.10).aspx

Hope that helps.

Best regards

John

John Goldsmith
www.visualSignals.co.uk
 

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