Create a Button that starts a Macro after a connector is drawn

Started by PhilippS, February 28, 2020, 02:42:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PhilippS

Hi there,

i've got to realise a button which essentially enables a macro which alters the next drawn connector.

So I tried to search for a way that it just references the properties of the SubShape i draw the connection from which should be the properties of the connector anyways or atleast thats what i want.

This is the code i use to alter my connector because after a connector is drawn its automatically selected which is totally fine but now i need to realise an Event/Trigger something like that so that i can press a button, lets say "video connector" which executes my macro for the next drawn connector. Anyone an Idea or an alternative Solution or approach to this problem?


Sub test1()

    Dim shp As Shape
    Dim conn As Connect
    Dim vsoLayer As Visio.Layer

           
    If ActiveWindow.Selection.Count > 0 Then
        Set shp = ActiveWindow.Selection(1)
    Else
        Exit Sub
    End If
   
           shp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "RGB(112,48,160)"
      shp.Cells("LineWeight").Formula = "0.5 pt"
         Set vsoLayer = ActivePage.Layers.Item("Video")
                vsoLayer.Add shp, 0

End Sub



best regards Philipp

wapperdude

Do you do this for all connectors, or only some?  You might want to consider making a custom connector and saving it.  That way it already looks the way you want?
Visio 2019 Pro

PhilippS

The task i'm trying to accomplish is that each connector will be altered after its drawn. If there is a possibility to do this over the shape I draw it from would be much easier otherwise i would have to do 5macros as the one i've posted for each different type of connector.
But i did not manage to tell my connector via vba to reference the shape i draw it from to overtake their properties like line thickness and color and maybe even the layer.
So its not about making one custom connector rather having a option to quicker alter my connectors after/before i draw them.


regards Philipp

wapperdude

Yes.  This is possible.  Assuming you've enabled Developer mode, click the Developer tab on the GUI.  In the Controls section, there's Insert pulldown menu...select  Command Button.  A button will be dropped on the page, and Visio will be put into Design Mode.  Right click thee button and you can edit the button, among other things, view / edit the code.  When done, exit Design Mode.  Now, left click the button will fire the macro.

Note, you can switch back to Design Mode if you want to edit the code or you can just go to Visual Basic Window and edit macro directly.

See attached for simple example.
Visio 2019 Pro