I like linking data to shapes in Visio. It saves time in filling in Shape Data and adding text, or any Data Graphic to them. Basically I am lazy, and I also like to create macros for repetitive tasks, so in this blog I provide two macros to save the drudgery of two tasks I do so often:
- Dropping and data linking a number of items from an External Data recordset filtered by values in a column or columns
- Connecting shapes together following a parent-child relationship between Shape Data values
I have provided these two macros in the DataRecordset Utils.vssm file which can be downloaded from at http://1drv.ms/1KPISVG, and as usual, I recommend putting the file into you My Shapes folder so that it can be opened easily, just like any stencil.
Dropping and data linking shapes filtered by column values
First of all, I use the OrgData.xls file (with two extra columns) that auto-generate hyperlinks provided with Visio as an example data source.
Secondly, I just dragged an dropped one row onto the page because this auto-creates a master called Rectangle.
Thirdly, I created some Data Graphics for this Shape Data, then deleted the shape.
These steps are only necessary for my example, but you could have your own External Data, master and Data Graphics.
By the way, I can see the name of a Data Graphic in the tooltip of a Data Graphic icon in the DATA \ Data Graphic dropdown gallery, or I could change its name with the right mouse menu.
The macro-enabled stencil appears as Drs Utils in when opened, and does not contain any shapes.
So, the first macro, DropFiltered, can be run when a master is selected in a stencil, and a row is selected in the External Data window.
This macro will open a dialog in which I can select the column, or columns, that contain the values in the selected row that I wish to filter by.
It also allows me to optionally select a Data Graphic to be applied to each shape when it is dropped in the page.
The second column displays the data type where 0 is text and 2 is number.
When I press Select, the matching rows are used to drop an array of the selected master shapes, each one linked to each data row.
This saves time on selecting individual rows.
Connecting shapes together following a parent-child relationship between Shape Data values
In noticed that the Marketing team reported to managers and directors that are not in the same Department, so I just found those three rows and dropped them into the page.
The next macro, ConnectFiltered, simply requires the Primary Key column, or columns, in the active External Data recordset to be specified, along with the column, or columns, that contains the values for the Parent Key. It also allows for optionally linking the connector shape to the data recordset row, and for applying a Data Graphic.
UPDATE : I have added the ability to optionally delete any existing connections on each shape – I found myself having to delete too often!
Then, when I click Select, the data values are followed to used to connect the data linked shapes on the page together using the Dynamic connector master shape.
I then used the DESIGN / Layout / Re-Layout Page gallery to choose a suitable style.
Alternatively, I could have selected a connector type (1D) shape in a stencil in order to use a specific master.
This give me flexibility to choose the appropriate style.
I hope this helps some users to create data-driven diagrams quicker, and replaces some of the functionality that Microsoft deprecated years ago when they cut-out the Flowchart and Network Diagram wizards….
Visio 2013 and later : http://1drv.ms/1KPISVG
Visio 2010 and earlier : http://1drv.ms/1QwH0WK
This stencil provides more generalised code for the action in a previous article : https://blog.bvisual.net/2009/02/24/creating-an-org-chart-without-the-org-chart-wizard/