Any ideas why DocumentOpened doesn't fire?

M

Michael Pollard

I just found something odd, and while I found an answer, I want it in here.

Problem: DocumentOpened, RunModeEntered, etc., events don't fire, even when
the application is first opened. My code is:
Public Sub Document_DocumentOpened(ByVal doc As IVDocument)
MsgBox ("Program started")
End Sub
and it doesn't do anything.

Apparent cause: One of my functions uses
Application.EventsEnabled = False
to keep events from firing lest it create an endless loop. I couldn't find
how to address the Enabled to a single event. The function apparently
crashed, leaving the events disabled, and apparently events stayed disabled
across Visio being closed, and even across restarting the computer.

If anybody has ideas about other possible causes, I'd love to hear them.

(I'd also like to know how to only disable a single event, specifically
SelectionChanged...)
 
M

Mark Nelson [MS]

One way to "disable" events is to use a flag to determine whether you should
respond to an event or not. This is often preferred to preventing the event
from firing at all. It also makes your application a good citizen because
there may be multiple add-ons listening to events.

Here is the basic approach:

1) Your app gets an event notification from Visio
2) You set a flag (e.g. global boolean variable) that indicates you are
handling events
3) You handle the event and make changes to the Visio diagram as needed
4) Visio fires events in response to your changes
5) Your app receives the event notifications but ignores them because the
flag is set
6) When you are done with your changes, you clear the flag

The key is to only respond to events if the flag is not set and to set the
flag when you do respond to an event.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Michael Pollard

That'll work. Thanks.

Mark Nelson said:
One way to "disable" events is to use a flag to determine whether you should
respond to an event or not. This is often preferred to preventing the event
from firing at all. It also makes your application a good citizen because
there may be multiple add-ons listening to events.

Here is the basic approach:

1) Your app gets an event notification from Visio
2) You set a flag (e.g. global boolean variable) that indicates you are
handling events
3) You handle the event and make changes to the Visio diagram as needed
4) Visio fires events in response to your changes
5) Your app receives the event notifications but ignores them because the
flag is set
6) When you are done with your changes, you clear the flag

The key is to only respond to events if the flag is not set and to set the
flag when you do respond to an event.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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