Author Topic: selfmade shortcuts in Visio 2010  (Read 76 times)

0 Members and 1 Guest are viewing this topic.

hidden layer

  • Newbie
  • *
  • Posts: 2
selfmade shortcuts in Visio 2010
« on: October 11, 2018, 05:56:56 AM »
Hi there,
neither in German or English environment I found an answer to the question:

Is it possible to create a shortcut in Visio 2010?

Actually I have to allocate hundreths of shapes to layers and always have to mouseclick layer -> add to layer... blabla.

I know, it's a more general question and I've read that it's possible to create a macro and I'm about to create one but I'm not really experienced with that. So if there is a solution out there I would appreciate any advice.

Thanks,
Peter

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2645
    • Paul Herber's website
Re: selfmade shortcuts in Visio 2010
« Reply #1 on: October 11, 2018, 08:38:56 AM »
You can do more than one shape at a time ...
But other than that ...
ribbon File  -> Options -> Quick Access Toolbar
Choose commands from: all commands
Scroll down to Assign to Layer
and click add.
The button is now on the quick access toolbar.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

http://www.paulherber.co.uk/

Yacine

  • Hero Member
  • *****
  • Posts: 2483
Re: selfmade shortcuts in Visio 2010
« Reply #2 on: October 11, 2018, 09:08:02 AM »
To extend Paul's advice, you can write a VBA form which once called lets you assign the layer to one shape after the other, or whole selections of shapes.
Make a form and add the following controls to it:
  • a list, name it ListValue
  • a text field, name it tValue
  • a checkbox, name it CheckAktiv
Set the showmodal value of the form to false.
And here's the code:
Code: [Select]
Option Explicit

Private WithEvents winObj As Visio.Window

Private Sub ListValue_Change()
    tValue.Value = ListValue.Value
End Sub

Private Sub UserForm_Initialize()
Dim temp As String
Dim arVals() As String
Dim f As Variant
   
    temp = "Layer1,Layer2,Layer3"
    arVals = Split(temp, ",")
    With ListValue
        For Each f In arVals
            .AddItem f
        Next f
    End With
    Set winObj = Application.ActiveWindow
End Sub

Private Sub winObj_SelectionChanged(ByVal Window As IVWindow)
    Dim shp As Visio.Shape
    Dim sel As Visio.Selection
    Set sel = ActiveWindow.Selection
    sel.IterationMode = visSelModeSkipSuper
    If sel.Count > 0 And CheckAktiv.Value Then
        For Each shp In sel
            setValue shp, tValue.Value
        Next shp
    End If
End Sub

Private Function setValue(shp As Visio.Shape, layerName As String)
    n = ActivePage.Layers(layerName).Index
    shp.Cells("layerMember").FormulaU = Chr(34) & n - 1 & Chr(34)
End Function

Note:
  • the layer names are hard coded. Change them to your needs or write something more dynamic.
  • the layer is only assigned if the checkbox is checked. This way you can uncheck the checkbox, do something else, recheck and resume the assigning process
  • the routine works with both single shapes and whole selections
  • the listbox is there to let you chose which layer to assign
I use this tool on a daily basis - not for layers, but to populate prop fields.

Viel Erfolg,
Y.
« Last Edit: October 12, 2018, 04:52:40 AM by Yacine »
Yacine

hidden layer

  • Newbie
  • *
  • Posts: 2
Re: selfmade shortcuts in Visio 2010
« Reply #3 on: October 12, 2018, 02:22:30 AM »
Hi Paul,
yes, the 'button' Assign to layer is already at the toolbar. The toolbar is meanwhile a bit huge...

@yacine:
Thanks a lot!
I've changed the script like this and that works great!
Code: [Select]
    Set winObj = Application.ActiveWindow
ListValue.Clear
For Each laylayer In ActivePage.Layers
    laylist = laylist & laylayer.Name & ","
Next
laylist = Left(laylist, Len(laylist) - 1)
    arVals = Split(laylist, ",")
    With ListValue
        For Each f In arVals
            .AddItem f
        Next f
    End With

Writing code is a Little bit different from Excel but it's not rocket science  ;)

Thanks a lot!!

Peter

But back to the question: is it possible to create own shortcuts? (as we know it from others)
« Last Edit: October 12, 2018, 02:24:07 AM by hidden layer »

Yacine

  • Hero Member
  • *****
  • Posts: 2483
Re: selfmade shortcuts in Visio 2010
« Reply #4 on: October 12, 2018, 03:20:59 AM »
Found this thread http://visguy.com/vgforum/index.php?topic=5424.0

I think you're better off with the macro above.
Yacine