Adding the Sixth Legend Icon in Visio 2010

In my previous two articles, I described how to have 6 icons in a Data Graphic Icon Set, and provided some VBA code to make your own icons sets from existing Visio shapes or images. One thing that I overlooked was the Insert Legend command in Visio 2010, because it does not add the sixth icon automatically, so this blog describes how to add it. As a side effect, the code also enables the legend labels of icon and CBV (Color By Value) items to be edited.


When you use the Insert Legend command, it examines the Data Graphics used on the active page, to create legends for each Icon Set or Color By Value settings that it finds. Closer examination of the legend shapes, shows that an instance of the Icon Set master shape is added for each of the icons found.


So, my method for having a sixth icon as the default if a match is not found present a problem, because it is not displayed automatically.

However, it is quite simple to add the sixth one. Select the icon above the one that is missing, then enter CTL+D to duplicate the shape, and notice that it will be added below it.

image image

So, now there are two icons that look the same, and are both labelled the same.

So, I decided to write a small macro to provide a simple way to display the default icon, and to change the text.

Firstly, the macro needs to recognise if the selected shape is actually a legend shape item for an icon set. This can be tested by checking that the cell User.msvDGLegendShapeType = “IconItem”

The label text is stored in the User.msvDGLegendText cell.


If the legend item is for an icon set, then the sub-shape has the cell User.msvCalloutType with the value “Icon Set” :


The displayed icon is controlled by the value in the User.msvCalloutIconNumber cell.

So, I wrote a macro, ChangeLegendTextOrIcon , that makes these changes simple:

Public Sub ChangeLegendTextOrIcon()
Dim shpLegendItem As Visio.Shape
Dim shpIconSet As Visio.Shape
Dim txt As String
Dim sNumber As String
Dim iNumber As Integer

    'Abort if no shape or too many shapes selected
    If Not ActiveWindow.Selection.Count = 1 Then
        Exit Sub
    End If
    'Abort if selected shape is not a legend item
    If ActiveWindow.Selection.PrimaryItem.CellExists("User.msvDGLegendShapeType", Visio.visExistsAnywhere) = 0 Then
        Exit Sub
        Set shpLegendItem = ActiveWindow.Selection.PrimaryItem
    End If
    'Prompt to change the label text
    txt = InputBox("Enter the desired label text", "Change Legend Text", _
    shpLegendItem.Cells("User.msvDGLegendText").FormulaU = "=""" & txt & """"
    'Prompt to change the icon number (not for CBVItem)
    If shpLegendItem.Cells("User.msvDGLegendShapeType").ResultStr("") = "IconItem" Then
        Set shpIconSet = shpLegendItem.shapes(1)
        sNumber = InputBox("Enter the icon number ( 0 to 4 normally, or anything else for the default) ", _
            "Change Legend Icon", Int(shpIconSet.Cells("User.msvCalloutIconNumber").ResultIU))
        If IsNumeric(sNumber) Then
            iNumber = Int(sNumber)
            shpIconSet.Cells("User.msvCalloutIconNumber").FormulaU = "=" & iNumber
            MsgBox "You must enter a number", vbInformation
        End If
    End If
End Sub


Then enter the desired icon number. For example, enter 5 to display the default icon:


The legend will now be changed as desired:



Similarly, you can use the macro to change the label of a CBV legend item. In this example, the header is not displayed on one line because the width of the column is controlled by the widest item. So, I selected one item and ran the macro:


I then added some spaces after the text:


This forced the whole column to be widened, thus providing enough width for the header text:


I have added the code to to the stencil from the previous blog – bVisualIconSetMaker.vss :!AoRdXTjKEAo1ii8gdbp4qu3qF8eK


One Response to “Adding the Sixth Legend Icon in Visio 2010”

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.


O365 and SharePoint

Simplify Tasks

Want to learn the simple way?

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

John Goldsmith's visLog

be smart, be clear, be visual ...

Mo's blog

Personal views on Dynamics 365 for Operations and Technical Architecture.

Chris Webb's BI Blog

Microsoft Power BI, Analysis Services, MDX, DAX, M, Power Pivot and Power Query

Azure Solutions for Office 365, and more...

Rob Fahrni



Life with Visio and other Microsoft Toys!

Nilsandrey's Weblog

Just another weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Smart graphics for visual people

%d bloggers like this: