I recently re-discovered an issue with callouts in Visio for a couple of projects that I am working on, and so I had to find a fix. The problem is that the callouts become dis-associated from their target shapes if either the layer visibility of the callout or the target shape is toggled off, and then back on again. This will result in a diagram with shapes without any connected callouts, so moving any of the target shapes will not move their associated callouts with them! I initially came up with a workaround that involved some jiggery-pokery with sub-shapes and layers, but it seems that the problem could have easily been averted if Microsoft had incorporated one specific User-defined Cell from the very start…
First, I should be clear which callouts I am talking about because the word has been used and abused over the years … This article refers to the callouts that are inserted from the Insert / Diagram Parts ribbon group. These are part of the Structured Diagrams concept that was introduced with Visio 2010.
I told the Visio development team about my findings and they trawled through the documentation that was originally created before the code base was passed from USA to India, and found this blog post. In short, there is an optional User.msvSDMembersOnHiddenLayer row, and, if it has a value, and if the value has a value of True then this disassociation would not happen at all.
Therefore I wrote a macro, FixCallouts(), to add this missing setting to any callout shapes in a document. This needs to re-run if any different types of callouts are added. I also discovered that there are two other requirements because of recent changes to Visio to add accessibility:
- Save the Visio document and re-open it to ensure that Visio heals inheritance of the User-defined Cells section because the Visio interface adds a row called visNavOrder to the shape instances
- Add the visNavOrder row to the master shape BEFORE adding msvSDMembersOnHiddenLayer
Note that the User-defined Cells section rows with black values are inherited from the master shape.
This is the code for the macro, with error trapping removed for brevity:
Public Sub FixCallouts() Dim mst As Visio.Master Dim shpMst As Visio.Shape Dim shp As Visio.Shape Dim mstCopy As Visio.Master Dim sect As Integer Dim row As Integer sect = Visio.VisSectionIndices.visSectionUser 'Loop through the Masters For Each mst In ActiveDocument.Masters Set shpMst = mst.Shapes(1) 'Check if structured (.IsCallout does not work in a master) If shpMst.CellExistsU("User.msvStructureType", _ Visio.VisExistsFlags.visExistsAnywhere) <> 0 Then 'Check if a Callout shape If shpMst.CellsU("User.msvStructureType").ResultStr("") = _ "Callout" Then If shpMst.CellExistsU("User.msvSDMembersOnHiddenLayer", _ Visio.VisExistsFlags.visExistsAnywhere) = 0 Then 'Open the master to edit it Set mstCopy = mst.Open Set shp = mstCopy.Shapes(1) 'May need to add User.visNavOrder first! If shpMst.CellExistsU("User.visNavOrder", _ Visio.VisExistsFlags.visExistsAnywhere) = 0 Then row = shp.AddNamedRow(sect, "visNavOrder", 0) End If 'Then add User.msvSDMembersOnHiddenLayer row = shp.AddNamedRow(sect, _ "msvSDMembersOnHiddenLayer", 0) shp.CellsU("User.msvSDMembersOnHiddenLayer").FormulaU = "=TRUE" 'Closing saves the changes mstCopy.Close 'Set the Match Master by Name on Drop to True to avoid duplicates mst.MatchByName = 1 End If End If End If Next mst End Sub
So, after running this macro an existing Visio document that contains callouts, the layers of either the callouts or the target shapes can be toggled without breaking the associations!
The macro can be downloaded from here. Simply save the macro-enabled stencil, FixCalloutsIssue.vssm, in your My Shapes folder, and open it within Visio when required. The macro can be run from View / Macros …
Tye E says
Hello David, This was a huge help and I can’t believe Microsoft hasn’t just configured this by default yet or at least in my testing hasn’t. One question, I have a master Template .vstx (not macro enabled) that I store in SharePoint Online and then call to the master Template from the Document Library so that when a new drawing is created it will leverage the master Template file which contains my stencil. The only catch is the Callout has to be use from the stencil and not from the >Insert >Diagram Parts menu to leverage the structured diagram callouts. My question is your Macro is saved on my machine in My Shapes folder, but how can I do this from an enterprise standpoint to be able to leverage the Macro in my master stencil? I’m not real skilled at Macros, but to attempt to answer my own question. I assume I somehow need to get the macro on a new macro enabled .vstm template file instead, but then I would have to enable Macros every time when prompted from a user standpoint. I’ve attempted but have been unsuccessful. The benefit of course would be that I could use any Callout shape instead of one from my stencil that has the 2 User Defined rows applied, which works like a charm by the way (Thank you). Just curious if there is a better way to enable for all callouts via a template stored in SharePoint online where I can leverage all callouts via macro or should I just cut my losses and go with the stencil Callout shape which will maintain the layers functionality?
David Parker says
If I understand correctly, you have a custom template that is used via SharePoint?
So, edit the custom template on your local PC, and add each of the Callouts to a page, and then delete them (not using Undo). This will add them to the usually hidden Document Stencil. Then run my macro, and save the template back to SharePoint.
The custom template will now contain the modified masters, and whenever a user drags a callout from a stencil or inserts from the ribbon, then the fixed master will be used because the Match master by name property is ticked.
Tye E says
David Thank you, this is way more simple this way and that worked great! I think I was overthinking it and forgot to consider that once the master was added to the page that it would cover the change that way. Really appreciate your help here and this isn’t the first time I’ve visited your site. Will you be doing any upcoming sessions at Ignite? Cheers!