How to get DesignModeEntered to Fire?

Started by Visio Guy, April 09, 2019, 08:07:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visio Guy

Has anybody ever gotten DesignModeEntered to do anything?

I've tried it in a VBA document:


Private Sub Document_DesignModeEntered(ByVal doc As IVDocument)
  Debug.Print "Document_DesignModeEntered" '//...never happens
End Sub


I even hooked up AddAdvise and tried to do it that way. Nothing.

The real problem I am having is with VBA and Ribbons. Every time I exit RunMode, then re-enter RunMode, I get a new custom ribbon group, as shown in the attachment. Of course, this only happens during development, and end-users won't have this, but I'd like to remove my custom ribbon when I exit RunMode.

Anybody have any ideas or experience?


For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Yacine

Hello Chris,

I tried your code snippet and indeed nothing happended. So (after having done a test with the recorder) I added a document_runmodeentered and suddenly both routines worked just fine.

Private Sub document_designmodeentered(ByVal doc As IVDocument)
    Debug.Print 123
End Sub

Private Sub Document_RunModeEntered(ByVal doc As IVDocument)
    Debug.Print 234
End Sub


Notice how the first method's name doesn't get properly rendered.

Cheers,
Y.
Yacine

Visio Guy

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

I still can't get it to work in VBA, but I do see that the Event Monitor shows the event happening, so it is possible somehow to detect the event:

1716 RunModeEntered Shape Totals and Data Transfer.vsdx  [/doc=1]
1718 VisioIsIdle
1768 DesignModeEntered Shape Totals and Data Transfer.vsdx  [/doc=1]
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Yacine

I don't know why it is not working for you.
I can just offer to provide you a copy of my file, where it works.
With some luck you may find the difference.
Yacine

Visio Guy

#5
Hmm. Doesn't work for me.

I even tried setting "Trust access to the VBA project objet model" to true, but that didn't help.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

wapperdude

#6
OK.  Did some investigating...

Took Yacine's alien named file and ran it.  Get warning about macros when file opens. After saying yes, macro runs and get 234.  Could not get 1st macro to fire.  No, 123.

Found this article:  https://docs.microsoft.com/en-us/office/vba/api/Visio.Document.Mode  If you haven't seen it, might be of value.

Well, decided to add a macro, see below.  I could get the DesignMode line to run, which then fired the DesignMode macro and generated 123.  Once in Design mode, executed the 2nd line of my macro, but the RunMode macro would not fire. 
I was only able to get the RunMode macro to fire upon opening the document, regardless if Developer Mode was checked or unchecked in the options.

Next, in the VB window, under Run, toggled the Design mode.  I could fire the RunMode macro, but not the DesignMode macro.

Whether things were capitalized or not had no bearing on the results.


Sub setMode()
'    ThisDocument.Mode = visDocModeDesign
    ThisDocument.Mode = visDocModeRun
End Sub
Visio 2019 Pro

wapperdude

#7
Well, now the good news...managed to get both macros to fire.

I noticed that my Developer tab lacked the DesignMode command  :o ...so I added it.  Pressing this button toggles between Design and Run modes and both macros will fire accordingly.   8)


Visio 2019 Pro

wapperdude

#8
Well, I'm not getting the point of this.  I thought I was.  Put Visio in Design mode, and it stops running macro.  No.  It stops running the macro statements within the macro that executed the Design Mode.  But, it doesn't prevent other macros from running.  It's more like a glorified exit macro command.  What's the point?  Same with the two command buttons. Seems like a waste of time...what was M$ thinking?  Setting security options seems to be the only way to stop macros from running.

Here's a quote from the link I previously provided: 
QuoteThis means that if code in a document's project sets the document's mode to design mode (ThisDocument.Mode = visDocModeDesign), the project in which the code runs transitions to design mode and any statements following the mode-assignment statement are not executed.

I must be missing something.
Visio 2019 Pro