Hi,
I can't seem to figure this one out ???
Is there a way to reference a child's property in a group by name? Or only by Sheet.ID?
Lets say i have a master "Olympic Flag" (With 5 children shapes named: Blue, Yellow, Black, Green, Red). When i drop the master shape, i give it a nameU of "FirstFlag". Is there any way to reference its child Blue ie "FirstFlag!Blue!FillForegnd". If its ID is 2, i can use "Sheet.2!FillForegnd" but is there a way to do this names?
Thanks,
Austin
You can reference a shape by it's name, but a group's sub-shape isn't a property, so you can't build up a dependencies tree.
Just a very fast first thought.
A very hackish way to do this would be to create multiple user defined cells that reference the sub shapes ID. Then you could simply reference the sub-shape via the user-defined cell values in the group sheet.
This doesn't allow you to use nameU; however it allows you to still have control over the sub shape you want to change without having to always know the shape.ID that is generated upon drop.
The attached image shows a shapesheet example of this from one of my own documents. These cells are defined in my master, and they update to the new shapeID upon drop. In my master the sheet reference is listed as Sheet.5!BeginX, and you can see here that it is now Sheet.3314. If I ever want to change the value of beginX via VBA, then all I need to know is the group sheetID (or NameU) of the group shape that is on the page. If I don't know the groupShape ID then I can retrieve it automatically via VBA. The following code excerpt only grabs the group shp.ID, but it can be modified to also retrieve the sub-selected shape ID if you want. In my documents, I have my group behaviors set to "Group Only" since my documents are very heavily automated.
Here is the code to retrieve the selected group shape ID.
Public Function gID() As String
Dim s As String
Dim shp As Visio.Shape
Dim sel As Visio.Selection
Set sel = Visio.ActiveWindow.Selection
sel.IterationMode = Visio.VisSelectMode.visSelModeSkipSub + _
Visio.VisSelectMode.visSelModeSkipSuper
If sel.count > 0 Then
s = s
End If
For Each shp In sel
s = s & shp.ID
Next
gID = s
End Function
In case I wasn't clear, the grouped shape must be selected in order to retrieve it. In order to automatically retrieve the sheet ID from inside your sub, all you need to do is define a string variable and then set it equal to the function name. I've included an example below:
Sub get_ID()
Dim shpID as string
shpID = gID
End Sub
Here are some other useful code snippets that can be used in the same way that I described in my previous posts.
I think this one came from David Parker but I'm not 100% certain on that; his function name was different than what I ended up using in the document that I pulled this from. This one will get the sub-selected shape ID if that is what you have selected.
Public Function ActiveShape_IP() As String
Dim s As String
Dim sel As Visio.Selection
Dim shp As Visio.Shape
Set sel = Visio.ActiveWindow.Selection
sel.IterationMode = Visio.VisSelectMode.visSelModeSkipSub + _
Visio.VisSelectMode.visSelModeSkipSuper
'// Header:
If sel.Count > 0 Then
s = s & vbCrLf
End If
'// Shape info:
For Each shp In sel
s = s & shp.ID & vbCrLf
Next
'// Get the sub-selected shapes:
sel.IterationMode = Visio.VisSelectMode.visSelModeOnlySub + _
Visio.VisSelectMode.visSelModeSkipSuper
'// Header:
If sel.Count > 0 Then
If (s <> vbNullString) Then s = s & vbCrLf
s = s & vbCrLf
End If
'// Shape info:
For Each shp In sel
s = s & shp.ID & vbCrLf
Next
ActiveShape_IP = s
End Sub
This next one looks pretty nice. I'm surprised I haven't come across it before; it's from http://visio.mvps.org/VBA/default.html. It gives you a full list of all the shapeIDs in a group; which means that you could then in turn use this to have the master dump this information into the pagesheet scratch section upon drop if you wanted. You can form all kinds of relationships this way; which is pretty handy if you build automation heavy documents.
This would would need some additional tweaking to be usable in the way that you need, but it wouldn't take much effort at all:
Public Sub ListGroup()
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Dim vsoShapes As Visio.Shapes
Set vsoSelect = Visio.ActiveWindow.Selection
If vsoSelect.Count > 0 Then
For Each vsoShape In vsoSelect
Call ProcessShape(shp)
Next vsoShape
Else
MsgBox "You Must Have Something Selected"
End If
End Sub
Public Sub ProcessShape(shp As Visio.Shape)
Dim subshp As Visio.Shape
Debug.Print shp.Name
If shp.Shapes.Count > 0 Then
For Each subshp In shp.Shapes
Call ProcessShape(subshp)
Next subshp
End If
End Sub
MsgBox "You Must Have Something Selected"
end if