Visio was the first non-Microsoft application to include VBA within it back in the mid-nineties. All of the desktop Microsoft Office applications currently include VBA, although Microsoft have been rumoured to want to replace it for many years, and now there is an alternative scripting option becoming available that is suitable for the web too.
Visio was acquired by Microsoft in 2000, and there are still many scenarios when it is useful to have VBA procedures available in Visio for the Desktop. These procedures can be created using the recorder, and then edited, or just created manually. Every Visio document can contain a VBA project, but it must be saved with the .vsdm extension for documents, .vssm extension for stencils, or .vstm extension for templates. The last letter, m, informs Windows that this file could contain macros, as opposed to the normal last letter x, which cannot. Even with this extension, users, or their IT department, may not enable the macros in Visio documents.
The CALLTHIS function in Visio can be used to run a procedure (sub-function) in a Visio Visual Basic document and pass through a reference to the shape that the function is called from. The Microsoft Docs provide an explanation of this useful technique, and it does describe some examples, but it does not show the VBA code that these examples need, nor does it show them working. It also does not make it clear that these procedures do not need to be in the Visio diagram document, but can be in a stencil that is open in the active Visio session. This is important because it means that VBA code can be centralised and distributed for use use on many other documents.[Read more…] about Using the CALLTHIS function in Visio