3

我目前正在尝试使用 VBScripts 来自动化 Visio。

我有一个 visio 形状“开始”,现有连接“Verbindung”指向“BeginX”并定位到“PosX”(因此具有动态结束)。

我没有设法修改动态端,因此它被粘在“Stop”的形状上。:(

有没有办法移动现有的连接器以便成功连接形状?

在此处输入图像描述

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

像这样的东西不起作用:

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

我也尝试使用“PosX”而不是“BeginX”,但效果不佳。:(

有人可以帮我吗?

4

1 回答 1

1

您似乎没有从您检索的 Connect 对象中获取形状参考。那么这样的事情怎么样:

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

如果您使用的是 Visio 2007,您可能会发现删除原始连接器并在 Shape 对象上使用AutoConnect方法更简单。如果您正在查看以前的版本,或者特别想处理哪些单元格粘合到哪个单元格,那么 Connects 和 FromConnects 会更好。

以下是这两种方法的几个 VBA 示例:

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

如果您运行这两个,您应该得到以下结果(注意 - 没有错误检查,并假设您从中调用代码的文档中存在母版):

Visio 形状连接

于 2013-03-20T20:47:50.483 回答