Select Visio shapes of the same type with VBA

I needed to select all the connectors on a sheet of the same master type, which in my case represent different cable types.

Individually selecting 50 or more connectors with 1mm spacing was not an option so I wrote this bit of code based on examples found at Visio Guy and Super User

Now I can select one shape and click a button to run the following code. All matching shapes will be selected.

Sub SelectSimilar()
‘ By Tim Norton – http://cctvdesign.online
‘ Select all shapes of the same kind on a page to allow bulk changes

Dim visShp As Visio.Shape
Dim sel As Visio.Selection

‘What is the reference shape to match others with
Set sel = Application.ActiveWindow.Selection
On Error Resume Next
For Each visShp In ActivePage.Shapes ‘ iterate throught the shapes on active page.
If Not visShp.Master Is Nothing Then
If visShp.Master = sel.Item(1).Master Then ‘ check for desired shape.
‘Add the selected shape to the selection
ActiveWindow.Select visShp, visSelect

End If
End If
Next

End Sub

Comments are closed.