Friday, May 30, 2008

Visio Org Charts: Change Border Color Based on a Custom Property

I recently was asked to modify an existing Visio Org Chart based on a custom property. Every person in the org chart had a custom property for a BlackBerry number. Based on whether the person had a blackberry number or not, my client wanted the border to be set to a thick red line.

I came up with the following code to do just that:

Sub set_blackberry_border_red()
Dim vsoPage As Visio.Page
Dim VsoShp As Visio.Shape
Dim i As Integer

For Each vsoPage In ActiveDocument.Pages
' Loop through each page
For Each VsoShp In vsoPage.Shapes
' Loop through every shape on the page
If Not VsoShp.OneD Then
' Shape is not a line
nrows = VsoShp.RowCount(Visio.visSectionProp)
' Set shape to normal border
black_border VsoShp
For i = 0 To nrows - 1
' Look at all properties
If VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsLabel).ResultStr(Visio.visNone) = "Blackberry" Then
' If property is blackberry phone number...
If VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsValue).ResultStr(Visio.visNone) <> "" Then
' ... set its border color to red
red_border VsoShp
End If
End If
Next i
End If
Next VsoShp
Next vsoPage
MsgBox "Finished.", vbInformation
End Sub

Sub red_border(shp As Visio.Shape)
' Set border size thicker
shp.CellsSRC(visSectionObject, visRowLine, visLineWeight).FormulaU = "1.2 pt"
' Set Border color to red
shp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "2"
End Sub

Sub black_border(shp As Visio.Shape)
' Set border size to thin
shp.CellsSRC(visSectionObject, visRowLine, visLineWeight).FormulaU = "0.24 pt"
' Set border color to black
shp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "0"
End Sub

2 comments:

  1. An alternate approach would be to modify the Orgchart master shapes so that the line colour of the shape is a formula based on the custom property.

    John... Visio MVP

    ReplyDelete
  2. Hello,I searched for a possibility to modify the Orgchart master shapes and did not find any. I am using Visio 2003. Could you please give me a hint? Thank you and best regards,

    Jens

    ReplyDelete

I moderate comments blog posts over 14 days old. This keeps a lot of spam away. I generally am all right about moderating. Thanks for understanding.