Solution-specific Visio Discussions > Artistic and Graphical Effects

selfmade shortcuts in Visio 2010

(1/2) > >>

hidden layer:
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.


Paul Herber:
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.

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 CheckAktivSet the showmodal value of the form to false.
And here's the code:
--- Code ---
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
--- End code ---

* 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 assignI use this tool on a daily basis - not for layers, but to populate prop fields.

Viel Erfolg,

hidden layer:
Hi Paul,
yes, the 'button' Assign to layer is already at the toolbar. The toolbar is meanwhile a bit huge...

Thanks a lot!
I've changed the script like this and that works great!

--- Code ---
    Set winObj = Application.ActiveWindow
For Each laylayer In ActivePage.Layers
    laylist = laylist & laylayer.Name & ","
laylist = Left(laylist, Len(laylist) - 1)
    arVals = Split(laylist, ",")
    With ListValue
        For Each f In arVals
            .AddItem f
        Next f
    End With
--- End code ---

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

Thanks a lot!!


But back to the question: is it possible to create own shortcuts? (as we know it from others)

Found this thread

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


[0] Message Index

[#] Next page

Go to full version