Here's some sample code for you.
Test runs FormatLines, which is the core smarts. Select a milestone shape
and run Test. FormatLines sets formulas in the sub-shapes inside the
milestone shape, such that you only need to change the LineColor of ths
shape.
A better option is to edit the master (in the document stencil of the
document you are editing). Then you only have to run FormatLines once for
each master that gets added to your drawing, all instances of that master
will be "smart" thereafter.
Your document has a MastersAdded event. When you first drop a new master
into a document, a copy of that master gets put in the document's
inner-stencil. See menu: File > Shapes > Show Document Stencil. Per
automation: Doc.Masters...
Sub Test()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection(1)
FormatLines shp, 3
End Sub
Sub FormatLines(shpGrp As Visio.Shape, lineColor As Integer)
Dim shpSub As Visio.Shape
Dim sGrpName As String
Dim sColFormula As String
sGrpName = shpGrp.NameID 'This will be something like 'Sheet.10'
shpGrp.Cells("LineColor").ResultIU = lineColor
For Each shpSub In shpGrp.Shapes
' The text sub shapes don't need to have the smart formula:
If shpSub.Text = vbNullString Then
' Okay, this is a normal sub-shape - set a formula to
' refer to the group's linecolor. An example formula:
'
' GUARD( Sheet.5!LineColor )
'
sColFormula = "GUARD(PAR!LineColor)"
sColFormula = Replace(sColFormula, "PAR", sGrpName)
shpSub.Cells("LineColor").Formula = sColFormula
End If
Next shpSub
End Sub
Sub EditMaster(shpGrp As Visio.Shape, lineColor As Integer)
If shpGrp.Master Is Nothing Then Exit Sub
Dim shpInside As Visio.Shape
Dim mst As Visio.Master, mstCopy As Visio.Master
Set mst = shpGrp.Master
Set mstCopy = mst.Open
Set shpInside = mstCopy.Shapes(1)
Call FormatLines(shpInside, 3)
mstCopy.Close
Set mst = Nothing
Set mstCopy = Nothing
End Sub
--
Hope this helps,
Chris Roth
Visio MVP