EventXFMod can cause Visio to stop working

I was recently re-working with some old code of mine that enhanced the Cross Functional Flowchart template, and found that it can cause Visio to stop working when the VBA project is enabled. Let me explain the problem, and the solution that I have adopted.
Firstly, I should say that this is VBA because it is for occasional use only, otherwise I would go to the trouble of making an add-in.
I modified the Flowchart shapes master by entering a formula in the EventXFMode cell:
=CALLTHIS(“GetFunction”,””)
This caused the GetFunction sub to be called whenever the shape was moved (in this case to detect the Functional band that it lay within).
This was working fine until the number of pages and shapes increased, and what I found was that, although it continued to work whilst the document was open, it caused Visio to stop working when the document was opened and the VBA project enabled. This always occurred whilst Visio was busy processing all of the shapes. It seems that my GetFunction sub was conflicting with whatever the Microsoft Cross Functional add-on and the Visio routing engine was up to.
I decided that the simplest solution would be find a way of filtering the firing of my GetFunction sub, and the easiest way to do this was to add a User-defined cell in the document, called MonitorShapes, and to only call my sub if the value in that cell is not zero, by using the modified formula in the EventXFMod cell:
=IF(TheDoc!User.MonitorShapes,CALLTHIS(“GetFunction”,””),0)
Of course, I then need sub to set this value to 0 or 1.
Public Sub StartMonitorShapes()
    If ThisDocument.DocumentSheet.CellExists("User.MonitorShapes", Visio.visExistsAnywhere) Then
        ThisDocument.DocumentSheet.Cells("User.MonitorShapes").Formula = "1"
    End If
End Sub
Public Sub StopMonitorShapes()
    If ThisDocument.DocumentSheet.CellExists("User.MonitorShapes", Visio.visExistsAnywhere) Then
        ThisDocument.DocumentSheet.Cells("User.MonitorShapes").Formula = "0"
    End If
End Sub
The result is that Visio no longer stops working when I open the document, as long as I remember to run StopMonitorShapes before I save and close it.
PowerShell.Amsterdam

Automate, Accelerate, Accurate

Rob Fahrni

I AM @FAHRNI

johnvisiomvp

Life with Visio and other Microsoft Toys!

Title (Required)

Windows Server Essentials Tips & Tricks

Nilsandrey's Weblog

Just another WordPress.com weblog

Things that Should be Easy

Every so often (too often in the IT industry) I encounter things that should have been very easy to do but turned out to be far too complicated. My favorite topics include SharePoint, .Net development, and software architecture, especially distributed systems.

Visio Guy

Shapes, Stencils, Drawings Templates, Tutorials, Tips & Developer Info for Microsoft Visio

Hannes's Virtual Earth

Tips & Tricks around Mapping and Cloud Computing

Pluralsight blog

be smart, be clear, be visual ...