Hi John,
I wrote this routine in VBA, note it does a few other things but you
can see in the testmode field = true it changes the color to 2 (which
is red). I basically use it to connect programmically dropped shapes.
Hope that helps.
Regards,
Garet
Usuage:
connectLine startShapeID, "left", endShapeID, "right", True
left/right are the connection names on the shapes, for example a box
would have left/right/top/bottom (these are named on the stencil shapes
themselves)
Sub connectLine(startID, startConnName, endID, endConnName, fldLine,
Optional connStyle = 16, Optional testMode = False, Optional grpID As
Double, Optional shpClass As String = vbNullString)
On Error GoTo connectLine_err
Dim dynamicLineID As Double
Dim vsoShape1 As Visio.Shape
ignoreDrop = True
Set vsoShape1 =
Application.ActiveWindow.Page.Drop(Application.ConnectorToolDataObject,
5.1211, 8#)
dynamicLineID = vsoShape1.ID
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsU("BeginX")
Set vsoCell2 =
Application.ActiveWindow.Page.Shapes.ItemFromID(startID).Cells("Connections."
& startConnName) '.CellsSRC(7, 1, 0)
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLOLineRouteExt).FormulaU = 1
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLORouteStyle).FormulaU = connStyle
vsoCell1.GlueTo vsoCell2
Set vsoCell1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsU("EndX")
Set vsoCell2 =
Application.ActiveWindow.Page.Shapes.ItemFromID(endID).Cells("Connections."
& endConnName)
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLOLineRouteExt).FormulaU = 1
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowShapeLayout, visSLORouteStyle).FormulaU = connStyle
vsoCell1.GlueTo vsoCell2
lineType = IIf(fldLine = True, "2", "1")
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowLine, visLinePattern).FormulaU = lineType
If testMode = True Then
Application.ActiveWindow.Page.Shapes.ItemFromID(dynamicLineID).CellsSRC(visSectionObject,
visRowLine, visLineColor).FormulaU = "2"
End If
ignoreDrop = False
Exit Sub
connectLine_err:
Select Case Err.Number
Case -2032466967 'Unexpected end of file
msg = "Unable to connect line"
MsgBox msg, vbExclamation + vbOKOnly, "Error Message
(connectLine)"
End Select
End Sub