3

I am currently triying to automate Visio by using VBScripts.

I have a visio shape "Start" having an existing connect "Verbindung" pointing to "BeginX" and targeting to "PosX" (therefore having a dynamic end).

I do NOT manage to modify the dynamic end, so that it is glued to shape "Stop". :(

Is there a way to move an existing connector so that the shapes are connected successfully?

enter image description here

Set startShape = CreateShape(visioApp,"ProzessSchablone.vss","Start",1,10)
Set stopShape = CreateShape(visioApp,"ProzessSchablone.vss","Stop",3,10)
Set startConnectedFrom = startShape.FromConnects.Item(1)    'to retrieve value: connect

Something like that does not work:

startConnectedFrom.Cells("BeginX").glueToPos stopShape,0.5,0.5

Also I tried for "PosX" instead of "BeginX", does not work as well. :(

Could anyone help me on that please?

murxx
  • 271
  • 1
  • 5
  • 9

1 Answers1

1

You don't appear to be getting the shape reference from the Connect object you've retrieved. So how about something like this:

Set shpConn = shpStart.FromConnects(1).FromSheet
Dim vFromCellStop As Cell
Set vFromCellStop = shpConn.CellsU("EndX")    
vFromCellStop.GlueToPos shpStop, 0.5, 0.5

If you're using Visio 2007 on then you might find it simpler to delete the original connector and use the AutoConnect method on the Shape object. If you're looking at a previous version or specifically want to deal with which cells glues to which then Connects and FromConnects are better.

Here's a couple of VBA examples of both methods:

Sub AutoConnectExample()
Dim shpStart As Shape
Dim shpStop As Shape
Dim vPag As Page

    Set vPag = ThisDocument.Pages(1)

    Set shpStart = vPag.Drop(ThisDocument.Masters("Start"), 1, 3)
    Set shpStop = vPag.Drop(ThisDocument.Masters("Stop"), 3, 1)

    shpStart.AutoConnect shpStop, visAutoConnectDirNone

End Sub



Public Sub ConnectWithGlueExample()

Dim shpStart As Shape
Dim shpStop As Shape
Dim vPag As Page
Dim shpConn As Shape

    Set vPag = ThisDocument.Pages(1)

    Set shpStart = vPag.Drop(ThisDocument.Masters("Start"), 5, 7)
    Set shpStop = vPag.Drop(ThisDocument.Masters("Stop"), 7, 5)

    Set shpConn = vPag.Drop(Application.ConnectorToolDataObject, 1, 1)

    Dim vFromCellStart As Cell
    Dim vToCellStart As Cell
    Set vFromCellStart = shpConn.CellsU("BeginX")
    Set vToCellStart = shpStart.CellsSRC(visSectionObject, visRowXFormOut, 0)

    Dim vFromCellStop As Cell
    Dim vToCellStop As Cell
    Set vFromCellStop = shpConn.CellsU("EndX")
    Set vToCellStop = shpStop.CellsSRC(visSectionObject, visRowXFormOut, 0)

    vFromCellStart.GlueTo vToCellStart
    vFromCellStop.GlueTo vToCellStop

End Sub

If you run these two you should get the following results (note - no error checking and assumes the masters exist in the document you're calling the code from):

Visio shape connections

JohnGoldsmith
  • 2,638
  • 14
  • 26
  • Hi John, thanks sooo much for your help - your first solution works perfectly! I also tried with the autoconnect - but then there was always a new connection along to the existing connection "Verbindung" created. But now it works, thank you!! :) Cheers - Doris – murxx Mar 21 '13 at 10:16