• 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 / Visio / Setting Visio Shape Cell Values By Connections

Published on April 20, 2008 by David Parker

Setting Visio Shape Cell Values By Connections

A recent newsgroup poster asked me to explain how to set the line color and weight of a connector according to the shapes it is connected to.  So, in this article, I have tried to explain one method of achieving this with minimal external coding.

In this example, I have created a rectangle shape that has a single Shape Data row, MyData, which has a fixed list of values, A;B;C.

The connector shape has been modified to trigger an event whenever a connection is made or unmade.  If the user successfully connects two rectangles with the same MyData value, then the line (weight and color) of the connector shape is amended to match the rectangle shapes.

image

The diagram below attempts to explain the relationships between the cells in the rectangle, connector and page.

image

The red arrows indicate the values updated by the VBA code; the green arrows indicate the values referenced from the page shapesheet, and the blue arrows indicate the values referenced within the same shapesheet.

Page

I modified the page shapesheet to have three new User-defined rows in order to have a centralised list of possible data values, and the corresponding line weights and colors for each value.  This is done with a simple semi-colon separated list, which could have been updated from an external data source.

User.MyDataList=”A;B;C”

User.MyLineWeights=”1pt;2pt;3pt”

User.MyLineColors=”RGB(255,0,0);RGB(0,255,0);RGB(0,0,255)”

In fact, these page cells could be inserted into the Master page of both the Rectangle and Connector shape (as in the sample diagram available below) and the act of dropping either master onto a new page will have the effect of duplicating these cells in the page shapesheet.

Rectangle

Then I modified a rectangle to have a new Shape Data row (Prop.MyData), where the format cell referenced the page User.MyDataList cell.

Prop.MyData.Format=ThePage!User.MyDataList

image

The line weight and color of the rectangle is changed with the following formulae:

LineWeight=GUARD(INDEX(LOOKUP(Prop.MyData,Prop.MyData.Format),ThePage!User.MyLineWeights))

LineColor=GUARD(INDEX(LOOKUP(Prop.MyData,Prop.MyData.Format),ThePage!User.MyLineColors))

Dynamic Connector

Now, in order to get the connector shape to fire an event whenever the connector shape is connected or disconnected, it is necessary to call a bit of code, ConnectIT, whenever the value in the BegTrigger or EndTrigger changes.  These cells are automatically updated whenever a connect or disconnect is done.

User.ConnectITTrigger=DEPENDSON(BegTrigger,EndTrigger)+CALLTHIS(“ConnectIT”,””)

User.BegIdx=0

User.EndIdx=0

I amended the LineWeight and LineColor formulae to respond to values in the User.BegIdx and User.EndIdx cells.

LineWeight=THEMEGUARD(IF(AND(User.BegIdx=User.EndIdx,User.BegIdx>0,ISERRVALUE(BeginX)=FALSE,ISERRVALUE(EndX)=FALSE),INDEX(User.BegIdx,ThePage!User.MyLineWeights),IF(CELLISTHEMED(FALSE),THEME(“ConnectorWeight”),SETATREFEXPR(THEME(“ConnectorWeight”)))))

LineColor=THEMEGUARD(IF(AND(User.BegIdx=User.EndIdx,User.BegIdx>0,ISERRVALUE(BeginX)=FALSE,ISERRVALUE(EndX)=FALSE),INDEX(User.BegIdx,ThePage!User.MyLineColors),IF(CELLISTHEMED(FALSE),SETATREFEXPR(THEME(“ConnectorColor”)),SETATREFEXPR(0))))

The bold characters are those bits that I added into the existing LineWeight and LineColor formulae, in order to check that the index of the values of the rectangle shapes at either end match each other.  If they do, then the line is changed too.

The ISERRVALUE(BeginX)=FALSE and ISERRVALUE(EndX)=FALSE part trap the changes due to either rectangle from being deleted.

VBA Code

Whenever the code is called, it clears the values in the User.BegIdx and User.EndIdx cells, then sets a formula to return the index of the value in the connected rectangle shapes, if they exist.

The following subroutine was added to a new module in the VBA project of the document:

Public Sub ConnectIT(ByVal shp As Visio.Shape)
If Visio.Application.IsUndoingOrRedoing Then
Exit Sub
End If
Dim cnx As Visio.Connect
'Ammended for Visio 2010 compatability
Dim beginFormulaSet As Boolean
Dim endFormulaSet As Boolean
Dim formula As String
Dim formulaWithName As String

For Each cnx In shp.Connects
    If cnx.ToSheet.CellExists("Prop.MyData", Visio.visExistsAnywhere) Then
        formula = "LOOKUP(Sheet." & cnx.ToSheet.ID & _
             "!Prop.MyData,ThePage!User.MyDataList)"
         formulaWithName = "LOOKUP(" & cnx.ToSheet.Name & _
             "!Prop.MyData,ThePage!User.MyDataList)"
         If cnx.FromCell.Name = "BeginX" Then
            If Not LCase(shp.Cells("User.BegIdx").formula) = _
                    LCase(formula) _
                And Not LCase(shp.Cells("User.BegIdx").formula) = _
                    LCase(formulaWithName) Then
                    shp.Cells("User.BegIdx").formula = "=" & formula
                End If
                beginFormulaSet = True
            ElseIf cnx.FromCell.Name = "EndX" Then
                If Not LCase(shp.Cells("User.EndIdx").formula) = _
                    LCase(formula) _
                    And Not LCase(shp.Cells("User.EndIdx").formula) = _
                    LCase(formulaWithName) Then
                    shp.Cells("User.EndIdx").formula = "=" & formula
                End If
                endFormulaSet = True
           End If
    End If
Next
If beginFormulaSet = False _
    And Not shp.Cells("User.BegIdx").formula = "0" Then
    shp.Cells("User.BegIdx").formula = "0"
End If
If endFormulaSet = False _
    And Not shp.Cells("User.EndIdx").formula = "0" Then
    shp.Cells("User.EndIdx").formula = "0"
End If
End Sub

Consequently, the connector shape responds to connections, disconnections and data changes in the connected rectangle shapes.

You can download the sample drawing here: http://sdrv.ms/OOIk2x or http://sdrv.ms/OOIpmW

Related

Filed Under: Connections, Connectors, VBA, Visio

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

Comments

  1. Jarrod says

    September 3, 2012 at 1:21 pm

    I keep getting a bizarre behaviour.

    Sometimes, the whole thing will go nuts, and run the trigger over and over again; forever.

    Oddly, it will run the function against the connector I just (dis)connected, then against a random other one (but it thinks it is not connected to anything), then against the selected connector forever.

    (I added a MsgBox call at the start of the function)

    The only way out is to go into task manager and kill Visio 2010.

    Any ideas?

    Reply
    • davidjpp says

      September 4, 2012 at 11:24 am

      Yipes, it does on my Visio 2010 laptop too!
      I’m just going to check in Visio 2007 ….

      Reply
      • davidjpp says

        September 4, 2012 at 11:33 am

        Well, It works OK in Visio 2007 … now I’ll try to work out why it goes crazy in Visio 2010.

        Reply
        • davidjpp says

          September 4, 2012 at 12:29 pm

          Thanks Jarrod for pointing this out … I have now updated the blog article and the downloads with revised code.
          It appears that Visio 2010 fires events in a different order, so I have refined the criteria for updating the cell formulas.
          Basically, I was able to get away with less perfect code before Visio 2010!

          Reply

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