Visio 2003: Stencil macros and new drawings

A

Aussie Susan

I think I'm missing something basic here....

I have a stencil that contains several shapes I have created, along with a
set of VBA code that is stored in the 'ThisDocument' module of the stencil.

I have also created a template that contains a blank page and the stencil
that I want.

I created the VBA code originally in the 'ThisDocument' module of a blank
drawing that I used to create the shapes and test their behaviour - this all
worked.

I have a 'sub Document_DocumentOpened' that I use to set the various
'WithEvents' variables to the active window and the document it contains
(which is not the stencil document but my actual drawing - at least that's
what it seems to me looking at the drawing '.name' property).

However, I am having trouble if I create a new drawing based on the template
file - not all of the macros are not triggered off by my actions. Those
connected to the window seem to be fired, but not those related to the
document (i.e. vsoWindow_SelectionChanged get called, but not
vsoDocument_ShapeAdded).

I think I have a fundamental lack of understanding about how VBA macros
should be used when they reside in the stencil. Is there some sort of
inheritance-like behaviour in how the events find their target procedures
(doubt it!) or is there something that I should be doing to initialise
everything when the document it opened?

Thanks

Susan
 
J

JuneTheSecond

A point to be checked might be that if drawing differs, the project differs.
You must refer to another project. But events for applicatrion and documents
might be treated in current project. For example,,

Option Explicit

Private WithEvents docs As Visio.Documents

Private Sub docs_DocumentOpened(ByVal doc As IVDocument)
MsgBox doc & " opened!"
End Sub

Private Sub Document_DocumentSaved(ByVal doc As IVDocument)
Set docs = Application.Documents
End Sub

JuneTheSecond
 
A

Al Edlund

Susan,
You're correct that there is an inheritance thing involved. The stencil is a
document unto itself sharing your 'master' document. I'd suggest you get a
copy of Graham Wideman's book (survival guide) where he discusses many of
the issues involved. You can find a reference on John Marshall's site
(visio.mvps.org)
al
 
A

Aussie Susan

June,

Thanks for the confirmation that I was on the right track.

I'll get hold of the book that Al Edlund recommended - it sounds like I'll
need it!

Susan
 
G

goldnhue

I'm having similar problem ...

I want to run a procedure, "DocLoad", that is located in a public module on
a stencil, whenever an object is dropped in a Visio Drawing. The following
call from the drawing's "Document_ShapeAdded" event generates error: Object
doesn't support property or method. Please help.

Code in the Drawing:
Private Sub Document_ShapeAdded(ByVal shape As Visio.IVShape)
Dim stnObj As Visio.Document
Set stnObj = Visio.Documents("StencilName.vss")
Call stnObj.DocLoad(shape)
End Sub

Code in the Stencil Module:
Public Sub DocLoad(shape As Visio.shape)
MsgBox "Shape Added."
'etc.
End Sub
 
D

David Parker

If you moved your DocLoad from the module to the ThisDocument class, then
everything would work OK.
Alternatively you would have to use ExceuteLine to call the module code, but
you would have to pass the arguments as a string, eg:

Private Sub Document_ShapeAdded(ByVal shape As Visio.IVShape)
Dim stnObj As Visio.Document
Set stnObj = Visio.Documents("StencilName.vss")

Call stnObj.ExecuteLine("DocLoadA " & shape.Document.Index & ","
& shape.ContainingPage.Index & "," & shape.Index)
End Sub


Public Sub DocLoadA(docidx As Integer, pageidx As Integer, shapeidx As
Integer)

Dim shape As Visio.shape
Set shape =
Visio.Application.Documents(docidx).Pages(pageidx).Shapes(shapeidx)
MsgBox "Shape Added."
'etc.
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top