Visio Guy

Visio Discussions => General Visio => Topic started by: Gunner22d on March 07, 2014, 01:40:05 AM

Title: Shortcut keys for macros in stencils
Post by: Gunner22d on March 07, 2014, 01:40:05 AM
Hi all.  I'm missing something really obvious.

I have a macro in a stencil.  I can run the macro from the editor just fine. I have assigned a shortcut key (Ctl+m).  When I press the shortcut key, the macro is not invoked.

This is part of a wider issue I have - about distrubuting some handy macros that I really need to run quickly, ie with a shortcut key.  I thought putting the code in a stencil was the right approach, I would be able to load he stencil and have the code available when I need it.

I've read the post on deploying code, but it is silent on shortcut keys. Any ideas on alternatives welcome.
Title: Re: Shortcut keys for macros in stencils
Post by: Paul Herber on March 07, 2014, 10:36:54 AM
Check your macro security settings. If you are distributing your code then you should consider getting a code signing certificate.
Title: Re: Shortcut keys for macros in stencils
Post by: Gunner22d on March 07, 2014, 07:08:54 PM
Thanks Paul

My security settings are wide open, and I want to invoke a macro in a stencil via a key press.  Can I do this? What is the best way to do this?  Thanks.
Title: Re: Shortcut keys for macros in stencils
Post by: Surrogate on March 07, 2014, 07:47:07 PM
I think shortcuts can invoked macros only in active document. External Stencil is not active document !
Title: Re: Shortcut keys for macros in stencils
Post by: Gunner22d on March 13, 2014, 11:10:25 PM
Thanks Surrogate.

I have a set of tools that I use for formatting shapes.  I like to use keyboard shortcuts.  I'd like to share them with friends. In Word, I can load a template into a known location, and when Word opens, the macros in this template are active for all Word documents.  I like this approach because it means that I can make changes to this template code, save it in the right place,  and then have it immediately available.  I'm looking for the nearest experience to this that I can get in Visio.

I see how I can load a macro in a template and attach it to a shortcut key.  I see how a document created from this template has a copy of this code (and shortcut) loaded. The important point is that this seems to be a copy of the code, because, when I change the code in the template, this is not available to my recently created document.  As far as I can see, I'd have to copy the new code into this document by hand for it to be available.

So the nuance is that I'd like shortcut keys and have some way of making code changes available in a fairly low touch kind of way. 

Many thanks for any suggestions.  :)
Title: Re: Shortcut keys for macros in stencils
Post by: Jumpy on March 14, 2014, 09:34:14 AM
I use a combination:

The "working" code is in a stencil named code.vss, that contains no shapes, only the code, and is distributed to all users.
In the template is a reference to that stencil in the VBA project, so the stencil's code "is known" in the template/drawing.
That stencil is not visible in the template, because I don't have it open in the stencil explorer. It is only open because of the reference in the VBA project.
The code in the template can be started via Shortcuts and does nothing except starting the "working" code in the stencil.

So I can make code changes in the stencil and "only" need to distribute that stencil again, to make the changes available for all users.

Problems:
If I want to create a completly new macro, I can distribute it with the stencil, so it's available for all, but you can't call that macro from older drawings, because there's no Shortcut available yet. The Shortcut is only available in new template/drawing.

So my solution is only a little bit better than yours because I can propagate code changes, but not entirely new code.

---------------

Another solution I'm thinking about:
- Scenario like above
- DocumentCreated or DocumentOpened event start a macro in the stencil.
- That macro creates a menu for all the available macros in the stencil.
- The menuitems get Shortcuts (don't know if that is possible)

So in theory the version of the stencil decides what code is available, as it should be.
Critical here is the last point: A way for the stencil to establisgh shortcuts....if it works.

Title: Re: Shortcut keys for macros in stencils
Post by: sybernut on October 14, 2015, 08:12:43 PM
Surrogate wrote: "I thisk [sic] shortcuts can invoked macros only in active document. External Stencil in not active document !"

True. Also, it seems that even if you import a *.bas macro file (into Modules VB directory) into a new active project/doc , the shortcut does not work in that project/doc although it appears in the Macros dialog (it only seems to work in the project/doc where the shortcut was originally created), as if shortcuts are actually stored in another area of the app... it can be made to work if you redefine it... but all of this (and more above) counteracts the purpose of macros.  I think these issues are due to the fact that MS did not create Visio from scratch like most of its other products, but acquired it and isn't bothering to update it with useful features.

So either I delve into VBA (loath) or forget about Visio macros... or perhaps Jumpy has come up with some code/process we can use effectively :)