Visio 2003: Document_OpenDocument in a stencil

A

Aussie Susan

I have a stencil that contains a 'ThisDocument' module which holds a
'Document_DocumentOpened()' method.

I create a new document from scratch (open Visio 2003, and use Ctrl-N to
create a new document) to which I add the stencil mentioned above (File ->
Shapes -> My Shapes -> stencilname).

At this point I would have expected the stencil's Document_DocumentOpened()
method to have been called.

I have Graham WideMan's"Visio 2003 Developer's Survival Pack" (and thanks to
those who have recommended this excellent book in my previous questions) and
I understand :

"...every Visio document (drawing, stencil or template) can have a
ThisDocument VBA module."

and

""Document events are commonly used to initialize extra drawing data ...when
a document is first opened (DocumentOpened event)..."

[quotes from page 294 of Wideman's book]

to mean that the stencils DocumentOpened event method should be called when
the stencil is opened as I have described above. However, debug.print and
msgbox statements in that method are not called and neither is the
initialisation code I have in there.

What am I doing wrong?

Thanks

Susan
 
A

Al Edlund

The first question I would ask is where are you watching for the event to
fire. As a test you might try to set a msgbox to fire from each of the
document opened events (one inside the stencil and one inside1 your new
master document). You didn't mention how you're testing to see if the event
has fired.
al

Aussie Susan said:
I have a stencil that contains a 'ThisDocument' module which holds a
'Document_DocumentOpened()' method.

I create a new document from scratch (open Visio 2003, and use Ctrl-N to
create a new document) to which I add the stencil mentioned above (File ->
Shapes -> My Shapes -> stencilname).

At this point I would have expected the stencil's
Document_DocumentOpened()
method to have been called.

I have Graham WideMan's"Visio 2003 Developer's Survival Pack" (and thanks
to
those who have recommended this excellent book in my previous questions)
and
I understand :

"...every Visio document (drawing, stencil or template) can have a
ThisDocument VBA module."

and

""Document events are commonly used to initialize extra drawing data
...when
a document is first opened (DocumentOpened event)..."

[quotes from page 294 of Wideman's book]

to mean that the stencils DocumentOpened event method should be called
when
the stencil is opened as I have described above. However, debug.print and
msgbox statements in that method are not called and neither is the
initialisation code I have in there.

What am I doing wrong?

Thanks

Susan
 
A

Aussie Susan

June,

Yes - the Automation Events are enabled. I normally have the Security level
set to 'medium' so I am asked to enable the macros (which I do) when the
stencil is opened. I have also tried at the 'low' security level but this
makes no difference to the activation of the stencil macro.

Al,

from my original post:

=====================
However, debug.print and
msgbox statements in that method are not called and neither is the
initialisation code I have in there.
=====================

Once I had the docment and stencil opened, I added the same code (minor
difference in the text so I could tell which was which) from the stencil
DocumentOpen macro in the document's DocumentOpen macro and saved the
document. When I opened the document again, I received the security warnings
about macros in both the document and the stencil, but the message box
displays and the debug print statements only occurred from the document macro
(not the stencil one)

Thanks for the assistance

Susan
 
A

Aussie Susan

Found the problem - and it relates to something that I had not mentioned in
my original post (of course!!!)

In the stencil file's ThisDocument module, I had several global (to the
module) variables declared with the 'WithEvents' keyword; one each for the
application, window and actual document (not the stencil).

The problem is that, as soon as I add the line:

Private WithEvents vsoDocument as Document

so that I could assign the actual drawing document to this variable, the
stencil Document_DocumentOpened macro stopped being called.

When I removed this line, the stencil's DocumentOpened macro was again called.

At least I now know the problem and I can develop alternative solutions.

Thanks to June and Al for your help

Susan
 

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