• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Using Visio in Education for GIS
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Visualize Complex Processes with Microsoft Visio
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Shape Design / ShapeSheet Formulas / Using Visio Color by Value on Connectors

Published on October 19, 2023 by David Parker

Using Visio Color by Value on Connectors

Data Graphics in Visio Plan 2 and Visio Professional is great, but it only enables us to use them with 2D shapes in Visio, i.e. not on connectors. So, what if you want to change the line colour of the connectors between the 2D shapes because of the data flowing between them? Well, it is possible … with a little preparation!

Firstly, you need data on your connectors … now that can be added manually, but more likely, you want to add the data from a data source like an Excel table. The good news is that you use Data | External Data | Custom Import … but you will want to have a unique identifier for each connector between shapes, unless you want to drag and drop each row from the External Data window on to each line … one by one. The smarter way is to create a Shape Data row value with unique id for each connector, and use this to import the data automatically.

The Dynamic connector master shape is the default connector in most Visio templates, and some of them already include a customised version of it. If you start a new blank diagram, then the Connector tool will automatically create the Dynamic connector master in the Document Stencil … and tick the Match master by name on drop option. Simply use Edit Master | Edit Master Shape from the right-mouse context menu of the master in the Document Stencil. Then add something like the FromID, ToID and ID Shape Data rows, as in the following screenshot.

  • The Dynamic connector master properties
  • The Dynamic connector master shape
  • The ShapeSheet of the Dynamic connector master shape

The FromID and ToID rows could be Invisible=True, and the Prop.ID.Value is set to the following formula:

=GUARD(Prop.FromID&”>”&Prop.ToID)

This Prop.ID.Value is the unique ID of the connector shape, and will be automatically created from the Prop.FromID and Prop.ToID values. Unfortunately there is no ShapeSheet formula to automatically get the value of a Shape Data row in the shapes that the connector is glued to at either end, so you will need a little code to update them. In this example, the Process shapes at either end of the connectors shapes have a Prop.ProcessNumber value, as shown by the numbers in the green Data Graphic Text callouts in the first screenshot. So, all that is needed is to transfer these values to the Prop.FromID and Prop.ToID Shape Data rows of each Dynamic connector shape. I wrote a little VBA to do this, but it could be in any suitable language.

I like to create some global constants to specify the names of the 1D connector master, the source Shape Data row of the 2D shapes, and the FromID and ToID Shape Data rows on the connector shapes.


Public Const MASTER_CONNECTOR As String = “Dynamic connector”
Public Const SHAPEDATA_SOURCEID As String = “ProcessNumber”
Public Const SHAPEDATA_FROMID As String = “FromID”
Public Const SHAPEDATA_TOID As String = “ToID”

Then you need a function to get the value of the source Shape Data row or an empty string if nothing found.

'Get the value of the named Shape Data row on a specified shape
'If numeric, then format it according to the format expression
Private Function GetIDFromShape( _
    ByVal shp As Visio.Shape, _
    ByVal propName As String) As String
On Error GoTo errHandler
    GetIDFromShape = ""
    If shp Is Nothing Then
        GoTo exitHere
    End If
    If shp.CellExistsU("Prop." & propName, _
            Visio.VisExistsFlags.visExistsAnywhere) Then
        If shp.CellsU("Prop." & propName & ".Type").ResultIU = 2 Then
            GetIDFromShape = format(shp.CellsU("Prop." & propName).ResultStrU(""), _
                shp.CellsU("Prop." & propName & ".Format").ResultStrU(""))
        Else
            GetIDFromShape = shp.CellsU("Prop." & propName).ResultStrU("")
        End If
    End If
        
exitHere:
    Exit Function
errHandler:
    MsgBox Err.description, vbExclamation, "GetIDFromShape"
    Resume exitHere
    Resume
End Function

Now, you are ready to loop through every connector shape on the active page to update the FromID and ToID values.

'Update every Dynamic connector on the active page with
'the specific Shape Data row values of each glued shape
'Clear the value if not glued
Public Sub UpdateDynamicConnectors()
On Error GoTo errHandler

Dim shpConnector As Visio.Shape
Dim mstConnector As Visio.Master
Dim selConnectors As Visio.Selection
Dim pag As Visio.Page
Dim cnxn As Connect
Dim fromID As String
Dim toID As String

    If MasterExists(MASTER_CONNECTOR) Then
        Set mstConnector = ActiveDocument.Masters(MASTER_CONNECTOR)
    Else
        GoTo exitHere
    End If
    
    Set selConnectors = ActivePage.CreateSelection(visSelTypeByMaster, 0, mstConnector)
    For Each shpConnector In selConnectors
        fromID = ""
        toID = ""
        For Each cnxn In shpConnector.Connects
            If cnxn.FromCell.Name = "BeginX" Then
                fromID = GetIDFromShape(cnxn.ToSheet, SHAPEDATA_SOURCEID)
            ElseIf cnxn.FromCell.Name = "EndX" Then
                toID = GetIDFromShape(cnxn.ToSheet, SHAPEDATA_SOURCEID)
            End If
        Next cnxn
        If shpConnector.CellExistsU("Prop." & SHAPEDATA_FROMID, _
                Visio.VisExistsFlags.visExistsAnywhere) <> 0 Then
            shpConnector.CellsU("Prop." & SHAPEDATA_FROMID).FormulaForceU = _
                "=""" & fromID & """"
        End If
        If shpConnector.CellExistsU("Prop." & SHAPEDATA_TOID, _
                Visio.VisExistsFlags.visExistsAnywhere) <> 0 Then
            shpConnector.CellsU("Prop." & SHAPEDATA_TOID).FormulaForceU = _
                "=""" & toID & """"
        End If

    Next shpConnector
    
exitHere:
    Exit Sub
errHandler:
    MsgBox Err.description, vbExclamation, _
        "UpdateDynamicConnectors"
    Resume exitHere
End Sub

You may already have data for each connector, but you can also create a basic table that contains each connection using a Shape Report, and then maybe use my free Shape Report Converter to turn the export into a proper table, suitable for enhancing with more data.

  • Export a Shape Report to Excel
  • Update using Shape Report Converter
  • Transform with Power Query

The next task is to use Data | External Data | Custom Import to link a table to Visio, and link to the connector shapes, as shown below.

  • Select all the shapes on the Connectors layer
  • Select Link… from the right mouse context menu
  • Link the selected shapes
  • Map the ID column to the ID Shape Data field

Now, you will find that Visio may automatically create some Data Graphics when it adds Shape Data to each connector, but you can configure them to suit your circumstance.

So, what has happened? Visio automatically added some User-Defined Cells and Shape Data rows to each data-linked connector. It creates a ShapeSheet formula in the User.visDGCBVFill cell to evaluate the values in the Color By Value settings, and then the LineColor cell gets the resultant colour value from this cell. Note that the contents of the cells that have values just for the instance of the master shape are displayed in blue automatically.

  • Value in Shape Data row defines the LineColor
  • Automatically created formula in User.visDGCBVFill

As you can see, Color By Value is not the only Data Graphic that can be applied to connector lines … you can also use the Data Bars, Icon Sets and Text callouts too….

So, as you can see, Data Graphics can be applied to connectors too!

A word of caution for Data Visualizer users: You cannot use the data linking technique explained in this article to do add more links to the connectors under the control of Data Visualizer. However, there is a work around, which I will explain in a future article.

Related articles

Fixing dimensions of 2D shapes

I am often asked what makes Visio unique and makes it stand out from the crowd, especially in today’s online world. Well, I think there are many reasons, but one of them is the ability to create scaled drawings with parametric components of specific dimensions. This was crucial for my adoption of Visio back in…

Merging Linked Data from Similar Tables

I was recently asked how to link data from different tables but with similar column names to Visio shapes. In this case, each table has the same unique identifier, but some of the column names are the same. The problem is that the data linking matches the column name with the label of a Shape…

Smart Radio Buttons and Check Boxes in Visio

A recent project requires an interactive tutorial within Microsoft Visio desktop where a lot of the questions need a single answer using radio buttons, or multiple-choice answers using check boxes. I thought that this would be a great use of the list containers capability because the questions and answers could be part of the container…

Using Button Face Ids in Visio

Microsoft Visio desktop has the ability to display icons from a built-in list of Office icons on Actions and Action Tags (nee Smart Tags). These can be set in the ShapeSheet by using the desired number from several thousand in the ButtonFace cell. Although there is the ability to add better icons using code, the…

Grid Snapping Revisited

I have previously tackled the subject of snapping to grids in Visio desktop (see https://bvisual.net/2018/06/19/really-snapping-to-grids-in-visio/ ) but a recent project required me to improve the example because it did not respond to all cursor arrow keys. The problem was that the previous solution could not understand which arrow key had been clicked, therefore it did…

Synchronizing Visio Shape Fill Color (or almost any cell) across pages

I was recently asked how the color of one shape can be changed and for other shapes to be automatically updated to the same color … even if they are on different pages! Well, it is possible with Microsoft Visio’s awesome ShapeSheet formulas. In fact, this capability is not limited to the FillForegnd cell ……

Related

Filed Under: Color, Data Graphics, External Data, Shape Data, ShapeSheet Formulas, VBA Tagged With: Data Graphics, Shape Data, ShapeSheet Functions, VBA

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Copyright © 2025 · Executive Pro on Genesis Framework · WordPress · Log in