Category Archives: 11331

Enhancing the Orgchart with different reporting lines

Over the summer I was asked if it was possible to have some of the reporting lines a different pattern. An interesting idea, but how do you mantain the feature when the Orgchart is imported and exported?

For this feature to work the information had to be stored with the person at the bottom of the reporting relationship. The Custom Properties (Soon to be Shape Data) of each person was preserved over imports and exports and was the ideal location. So once the data was imported into Visio VBA code was run to check each 2d shape for a "Reporting Type" Custom Property and change the line pattern of their reporting line to match.

Sub ChangeReportingLines()

' Display connections on the page

Dim conObj         As Visio.Connect
Dim i              As Integer
Dim ReportingType  As String
Dim vsoPage        As Visio.Page
Dim VsoShp         As Visio.Shape

For Each vsoPage In ActiveDocument.Pages
    For Each VsoShp In vsoPage.Shapes
        If Not VsoShp.OneD Then
            nrows = VsoShp.RowCount(Visio.visSectionProp)
            For i = 0 To nrows – 1
                If VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsLabel).ResultStr(Visio.visNone) = "ReportingType" Then
                    ReportingType = VsoShp.CellsSRC(Visio.visSectionProp, i, visCustPropsValue).ResultStr(Visio.visNone)
                    For Each conObj In VsoShp.FromConnects
                        If conObj.FromPart = visEnd Then
                        Debug.Print "change to –> "; ReportingType
                        Select Case ReportingType
                        Case "Dotted"
                            conObj.FromSheet.CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = "3"
                        Case "Dashed"
                            conObj.FromSheet.CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = "2"
                        Case Else
                            Debug.Print ReportingType
                        End Select
                    End If
                    Next conObj
                End If
            Next i
        End If
    Next VsoShp

Next vsoPage

End Sub

This can be taken further by trapping any changes to the line pattern through the UI and updating the Custom Property to match.

John… Visio MVP

How do Borders and Title shapes stretch to fit the page?

When dropping a border or title shape on a page, it automatically stretches to fit the page, but if you look at the shapesheet for the dropped shape, Width and Height are fixed. How do they do that?

The trick is that the shape on the stencil has an EventDrop cell that tells Visio to set the values of Width, Height, PinX and PinY to fixed values when the shape is dropped on a page. It also tells Visio to clear the EventDrop cell so the process can not be repeated by the copy.

You can find samples of these shapes by looking in the “Background” “Border and Titles” stencils. When you look ath these shapes, you will find that these shapes define their size based on the page size using the following formula:

Width =ThePage!PageWidth-4*User.PageMargin

The value for the PageMargin row in the User Section is a bit involved to repeat here, but it sets the margin off the shape based on the scaling factors in use.

The EventDrop cell uses SETF and GETF to assign the initial formula to the four cells and then replace it with the formulas value. I have broken the formula into its’ five components to make it more readable. In reality, the formula in the EventDrop cell below is one long string. 


 The final SETF clears the EventDrop cell.

A similar method is used for Background pages, but the formulas are not cleared

Width =GUARD(ThePage!PageWidth)

Unlike the Borders and Titles shapes, the Background shape needs to run an add-on to place the shape. The EventDrop cell contains:

=RUNADDON(“Make Background”)+SETF(“EventDrop”,0)

The “Make Background” is a Private add-on which will create a background page called VBackground, place and resize the shape and then add the background page reference to the foreground page.

John…    Visio MVP