News:

Happy New Year!

Main Menu

Visio Events Not Always Firing

Started by OldSchool1948, September 03, 2024, 12:36:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

OldSchool1948

I'm developing a rather complex application using Visio and VBA. I am making extensive use of Windows, Document, Page, and Shape events in the ThisDocument module. When a document is initially opened, all events fire as they should, and users have not complained about any event related "bugs."

On the other hand, during development/debugging, Visio events will sometimes stop firing even when Application.Events = True.  In addition, when toggling in and out of Design Mode, the Document.DocumentOpened event sometimes fires. When events stop firing, I have to close and reopen my development document to get them working again. I have not found a way fix the Design Mode toggling/Document.DocumentOpened event not firing problem.

Is there any way to restart event firing when Application.Events = True and they are not firing, or a way to force the Document.DocumentOpened event to always fire when switching in and then out of Design Mode?

Surrogate

Quote from: OldSchool1948 on September 03, 2024, 12:36:58 AMOn the other hand, during development/debugging, Visio events will sometimes stop firing
You mean "Step into" (F8) method of debugging? 
When I use this method, dont works Ctrl+C/Ctrl+V...

Nikolay

Quote from: OldSchool1948 on September 03, 2024, 12:36:58 AMI'm developing a rather complex application using Visio and VBA

Well, that sounds bad enough already ;D

Quote from: OldSchool1948 on September 03, 2024, 12:36:58 AMIs there any way to restart event firing when Application.Events = True and they are not firing, or a way to force the Document.DocumentOpened event to always fire when switching in and then out of Design Mode?

I don't think so. But you can always file a bug using the "Feedback" button. Most probably it won't help either, but you will feel better :)

Thomas Winkel

I guess that you have some code like that in your stencil to initialize the objects:
Option Explicit

Private WithEvents vApp As Visio.Application

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
    Set vApp = Application
End Sub

Private Sub SetVisioApplication()
    Set vApp = Application
End Sub

' Your events here...

If your application crashes, the objects may lose their reference (vApp is nothing).
Then you can use SetVisioApplication() to initialize manually without restart.
Of course, this is just a makeshift for development where frequent crashes are part of the process.

wapperdude

As Sgt Shultz would say..."I know nothing!!!"

Nevertheless, perhaps this link might be useful to maintain a well defined "application" application.  No, I didnot stutter.  https://learn.microsoft.com/en-us/office/vba/api/Visio.Application.Application
Visio 2019 Pro

Yacine

Thomas has made a good point.
In my solution - also VBA based - in each routine that involves one on the main objects (vApp, vWin, Vpg, vDoc) I perform a fast "sanity" check: if not getVisioShort then ...

getVisioShort is a function returning a boolean.
It starts something like if not vPg is Nothing then return True,
Else try to re-initialize the variables: getVisio
if getVisio = true then getvisioshort is true
else = false.
Yacine

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 274 (show)
Files included: 32 - 1207KB. (show)
Memory used: 1162KB.
Tokens: post-login.
Cache hits: 14: 0.00179s for 26,592 bytes (show)
Cache misses: 4: (show)
Queries used: 16.

[Show Queries]