Custom Keyboard shortcuts to invoke a custom action menu item.

Started by bwharrington, August 22, 2019, 08:44:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bwharrington

I've scoured the internet for examples of how to implement a custom keyboard shortcut but nothing is really panning out.

In an idea world I would like to be able to CTRL+Y to invoke a custom action menu item or just a method in my code.

A couple things I have found indicate this may not be possible. However I think these are outside the realm of writing code to solve the problem. At least Id like to believe that.

http://visguy.com/vgforum/index.php?topic=4122.msg16055#msg16055
https://superuser.com/questions/698650/how-can-i-set-my-own-custom-keys-for-shortcuts-in-visio-2013

However if you check one of the reference sites you can find visCmdCreateShortcut,

https://docs.microsoft.com/en-us/office/vba/visio/Concepts/docmd-docmd-commands

Does anyone have examples or insight on how this may be achieved? Possibly using visCmdCreateShortcut or a command similar to it?

Thanks,

Gustavo

the "quick and dirty", but easiest way is:

Private Sub actiontrigger1 ()
    Dim shp As Visio.Shape
    Dim cellname As String
    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(31), visSelect  ' 31 being the shape ID of the shape containing the action cell to trigger
    Set shp = ActiveWindow.Selection(1)
    cellname = "Actions.Action_Row1.Action" 'This being the action cell to trigger
    shp.CellsU(cellname).Trigger
End Sub


And then assign a keyboard shorcut to the macro. You can do it with the Macro Options.
The other way would be using the Application.Keydown event listener : https://docs.microsoft.com/en-us/office/vba/api/visio.application.keydown and then using it at the beginning of the code with an If then...

good luck.