我目前正在尝试使用VBScripts自动化Visio。
我有一个visio形状“开始”,现有连接“Verbindung”指向“BeginX”并定位到“PosX”(因此具有动态结束)。
我无法修改动态结束,因此粘贴形状“停止”。 :(
有没有办法移动现有连接器以便成功连接形状?
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”,也不行。 :(
有人可以帮我吗?
答案 0 :(得分: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
如果你运行这两个,你应该得到以下结果(注意 - 没有错误检查,并假设你正在调用代码的文档中存在主人):