Author Topic: How to get DesignModeEntered to Fire?  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1644
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
How to get DesignModeEntered to Fire?
« on: April 09, 2019, 03:07:01 AM »
Has anybody ever gotten DesignModeEntered to do anything?

I've tried it in a VBA document:

Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 2580
Re: How to get DesignModeEntered to Fire?
« Reply #1 on: April 09, 2019, 02: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.

Code: [Select]
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1644
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: How to get DesignModeEntered to Fire?
« Reply #2 on: April 09, 2019, 02:13:11 PM »
des iss a woansinn!
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1644
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: How to get DesignModeEntered to Fire?
« Reply #3 on: April 10, 2019, 06: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]
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

  • Hero Member
  • *****
  • Posts: 2580
Re: How to get DesignModeEntered to Fire?
« Reply #4 on: April 11, 2019, 01: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.
Yacine

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1644
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: How to get DesignModeEntered to Fire?
« Reply #5 on: April 15, 2019, 11:42:17 AM »
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.
« Last Edit: April 15, 2019, 11:44:42 AM by 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

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3474
  • Ideas Visio-lized into solutions
Re: How to get DesignModeEntered to Fire?
« Reply #6 on: April 15, 2019, 07:16:44 PM »
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.
 
Code: [Select]
Sub setMode()
'    ThisDocument.Mode = visDocModeDesign
    ThisDocument.Mode = visDocModeRun
End Sub
« Last Edit: April 15, 2019, 07:18:23 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3474
  • Ideas Visio-lized into solutions
Re: How to get DesignModeEntered to Fire?
« Reply #7 on: April 15, 2019, 07:27:10 PM »
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)


« Last Edit: April 15, 2019, 09:19:52 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3474
  • Ideas Visio-lized into solutions
Re: How to get DesignModeEntered to Fire?
« Reply #8 on: April 20, 2019, 11:24:22 PM »
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: 
Quote
This 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.
« Last Edit: April 23, 2019, 09:29:47 AM by wapperdude »
Visio 2019 Pro