Easier way to identify collection of shapes?

B

ben h

Hello, at the moment I'm doing the following to identify the shapes on
the active page as belonging to a particular master. I'm sure there must
be a simpler, more direct way?

Private Sub IdentifyShapes()
Const MasterName = "ActivityText"
Dim PageShapes As Visio.Shapes
Dim shp As Visio.Shape

Set PageShapes = Visio.ActivePage.Shapes

For Each shp In PageShapes
If shp.Master.Name = MasterName Then
'' this is a shape we like
End If
Next shp
End Sub
 
M

Mark Nelson [MS]

Check out the CreateSelection method in Visio 2003. It allows you to
specify a particular master.
 
J

JuneTheSecond

Thanks, Mark

It is what ben h is looking for.
Dim vsoSelection As Visio.Selection
Dim myMaster As Visio.Master

Set myMaster = ThisDocument.Masters("ActivityText")
Set vsoSelection = ActivePage.CreateSelection _
(visSelTypeByMaster, visSelModeSkipSub, myMaster)

Application.ActiveWindow.Selection = vsoSelection

There also is an example at "Visimation Shape Source Forum",
http://www.shapesource.com/forums/topic.asp?TOPIC_ID=777
 
D

David Parker

BTW, you should check if a shape has a Master before calling
shp.Master.Name,
eg If not shp.Master is nothing then ...
 
B

ben h

Mark said:
Check out the CreateSelection method in Visio 2003. It allows you to
specify a particular master.

Mark, thanks for all your replies to all of my recent questions! They've
been spot-on.
It's certain there'll be more...
Ben
 
B

ben h

David said:
BTW, you should check if a shape has a Master before calling
shp.Master.Name,
eg If not shp.Master is nothing then ...

David,
Thanks for the warning!

This is where VBA suffers from not having shortcut statements (or
whatever they're called). It would be much nicer if we could write:

If (Not shp.Master Is Nothing) And (shp.Master.Name = MasterName) Then
....

and have the statement exit at the first False value, rather than nest
if statements.

Ben
 

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