Hi, I'm working on a network diagram project and having trouble figuring out how to select all current members of a visio container with VBA.
I have a macro in excel that reads large lists of network connections and draws visio diagrams from it. This seems simple enough but I can't seem to nail it.
First I tried recording myself right-clocking on the container and choosing >>container >>"select contents" but the resulting code simply selects each shape by ID one at a time (presumably because this command already knows how many shapes there are in conatiner and their IDs).
I need code that works without me knowing this, hope that makes sense. I did find a function that iterates through all members of a container and makes a collection of each ID, but I can't make the next leap to use this to select all of these shapes. I'm probably missing something easy, any help much appreciated. Using Visio 2010 and Excel 2010. Here's the appropriate portion of the code, and the spot where I think I need help:
' get an enumerable list of shape ids that are already in the container
Dim colMembers As Collection
Set colMembers = getMembersOfContainer(vsoContainerShape)
Dim shapeSelection As Selection
If 0 < colMembers.Count Then
Dim intX As Integer
For intX = 1 To colMembers.Count
If colMembers.Item(intX) = visShape.ID Then
"some code that adds each vis.Shape to the current selection"
Exit For
End If
Next intX
End If
above code uses this function:
' pass in a container and return a collection of shapeIds
'
Public Function getMembersOfContainer _
(ByRef vsoContainerShape As Visio.Shape) _
As Collection
On Error GoTo ErrHandler
Dim colReturn As Collection
Set colReturn = New Collection
Dim arrMember() As Long
arrMember = vsoContainerShape.ContainerProperties.GetMemberShapes(VisContainerFlags.visContainerFlagsDefault)
Dim memberId As Long
Dim intI As Integer
For intI = 0 To UBound(arrMember)
colReturn.Add (arrMember(intI))
Next
Set getMembersOfContainer = colReturn
Exit Function
ErrHandler:
Debug.Print "getMembersOfContainer " & Err.Description
Set getMembersOfContainer = colReturn
End Function