Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visio Guy on April 09, 2019, 08:07:01 AM

Title: How to get DesignModeEntered to Fire?
Post by: Visio Guy on April 09, 2019, 08:07:01 AM
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?


Title: Re: How to get DesignModeEntered to Fire?
Post by: Yacine on April 09, 2019, 07:07:08 PM
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.
Title: Re: How to get DesignModeEntered to Fire?
Post by: Visio Guy on April 09, 2019, 07:13:11 PM
des iss a woansinn!
Title: Re: How to get DesignModeEntered to Fire?
Post by: Visio Guy on April 10, 2019, 11:59:47 AM
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]
Title: Re: How to get DesignModeEntered to Fire?
Post by: Yacine on April 11, 2019, 06:45:18 AM
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.
Title: Re: How to get DesignModeEntered to Fire?
Post by: Visio Guy on April 15, 2019, 04:42:17 PM
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.
Title: Re: How to get DesignModeEntered to Fire?
Post by: wapperdude on April 16, 2019, 12:16:44 AM
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 (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
Title: Re: How to get DesignModeEntered to Fire?
Post by: wapperdude on April 16, 2019, 12:27:10 AM
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)


Title: Re: How to get DesignModeEntered to Fire?
Post by: wapperdude on April 21, 2019, 04:24:22 AM
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.