I wrote a post a few years ago entitled How to Run VBA Macros from a Ribbon Button in Visio 2010, and was recently asked how to add the custom buttons to an existing tab. Well, it got me thinking that I don’t really like having any VBA code in my Visio diagram documents, so I thought I would explain how all the code can be in a macro-enabled stencil so that it can be used with many different diagram documents. It turned out to be a very easy modification….

Simply copy all of the code from the RibboMacros.vsd, from the previous article, into a macro-enabled stencil and make a slight modification to the LoadRibbon() and UnloadRibbon() functions by replacing ThisDocument with Nothing.
Option Explicit
Private Sub Document_DocumentOpened(ByVal Doc As IVDocument)
'Open the custom ui
LoadRibbon
End Sub
Private Sub Document_BeforeDocumentClose(ByVal Doc As IVDocument)
'Remove the custom UI
UnloadRibbon
End Sub
Public Sub LoadRibbon()
CustomUIStart Nothing
End Sub
Public Sub UnloadRibbon()
CustomUIStop Nothing
End Sub
That’s all there is to it, because now the buttons will appear whenever the stencil is opened, and disappear whenever it is closed.
Counting glued and connected shapes in Visio
I got a surprise in one of my projects when I counted the shapes glued together using the Shape.GluedShapes(…) method … the sum of the filtered glued shapes just didn’t add up to the unfiltered count. So, I thought I should check the Shape.ConnectedShapes(…) method too … and there is a scenario where that has…
A Visio List Shape is also a Container
Structured diagrams have been around in Microsoft Visio since 2010 and I have always known that list shapes are a specialized container shape, however it still came as a surprise to me recently that a list shape can simultaneously act as a container shape! There are a few examples of both container and list shapes…
Duplicating Visio Data Graphics
I was recently asked about switching between different Visio Data Graphics within a page, so I thought I should record a few short videos to explain how Visio Data Graphics work, how they can be edited and duplicated, and how to automate switching between them. (more…)
Referencing Visio Shapes
Every Visio shape must have a unique name in the collection that it belongs to, and to ensure this, Visio automatically one using the master name or just “Sheet”, if not an instance of a master, followed by a period (“.”) and the ID. However, a user can rename a shape, and Visio will then…
Bi-directional Labels on Off-Page Grid References
I have previously written about using off-page references and labelled page grids in Visio, see A Page Grid with Labels and Page Grids and Off Page References, however a reader pointed out that the label on the Off-Page Reference shape is duplicated on both ends. This is not always ideal, however it is all I…
Assigning Visio Shapes to Layers from Excel Table
I work a lot with layers in Visio, and written an add-in, LayerManager, to assist, but I was asked an interesting question recently: How can shapes by assigned to layers automatically from a list in Excel? So, I thought I would present my solution. This particular request was for a Timeline diagram, where the Milestone…
Leave a Reply