Q1:
The macros are running from the stencil.
No need to enable macros for the document.
With the Visio Object model you can directly access everything within the current application:
- Application returns the current application.
- ThisDocument returns the document where the code is running.
- ActiveDocument returns the active document.
- ActivePage returns the active page.
- ActiveWindow returns the active window.
This example prints the same result to Immediate window, regardless if running from document or stencil:
Option Explicit 'Always use "Option Exlicit"
Sub IterateThroughAllShapesWithinCurrentVisioApplication()
Dim doc As Visio.Document
Dim pge As Visio.Page
Dim shp As Visio.Shape
'Never use this (except you really know what you are doing):
'On Error Resume Next
For Each doc In Application.Documents
Debug.Print "* " & doc.Name
For Each pge In doc.Pages
Debug.Print "....* " & pge.Name
For Each shp In pge.Shapes
Debug.Print "........* " & shp.Name
Next shp
Next pge
Next doc
End Sub
Btw. Visio Documents, Stencils & Templates are the exactly same object types: Visio.Document
Only the filename extension differs and tells Visio how to handle it.
Q2:
Before you edit a stencil you should set it to "Edit" mode via context menu (see attached screenshot).
Before adding master shapes this is mandatory, but before editing code it's easy to forget.
Extra tip:
In the VBA editor, goto Tools -> Options...
Uncheck "Auto Syntax Check"
Check "Require Variable Declaration"
(See second screenshot)