Visio Stencil Sort

One of the things I noticed when reviewing Visio’s User Voice was the request for being able to have the shapes (they are actually masters) in the stencils be sorted. This is some code I have for keeping the masters in the document stencil sorted.

Here is the before and after.

Public Sub SortStencil()
Dim i As Integer
Dim j As Integer
Dim pntr As Integer
Dim lastmst As String
Dim mstrcnt As Integer
mastrcnt = ThisDocument.Masters.Count
For i = 1 To mastrcnt
    lastmst = ""
    pntr = 0
    For j = i To mastrcnt
        If ThisDocument.Masters(j).Type = 1 Then
            If ThisDocument.Masters(j).Name > lastmst Then
                lastmst = ThisDocument.Masters(j).Name
                pntr = j
            End If
        End If
    Next j
    If pntr > 0 Then ThisDocument.Masters(pntr).IndexInStencil = 1
Next i

End Sub

I hope you guys can helps.

John… Visio MVP in x-aisle

Published by johnvisiomvp

The original Visio MVP. I have worked with the Visio team since 1993

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s