【发布时间】:2018-07-10 19:31:09
【问题描述】:
我想通过 VBA 将一个形状粘合到另一个形状上。 所有的形状都是用一个用户窗体模块创建的。 我希望某些形状与箭头连接(也通过用户窗体拖放到页面上)。它可以很好地连接两个不在一个组中的形状。现在我想连接两个形状,其中一个或两个可能在一个组中。
这适用于非分组形状
'get shp, src, aim
[...]
shp.Cells("BeginX").GlueTo src.Cells("PinX")
shp.Cells("EndX").GlueTo aim.Cells("PinX")
我使用这个函数获得了目标和 src 形状:
Function getShape(id As Integer, propName As String) As Shape
Dim shp As Shape
Dim subshp As Shape
For Each shp In ActivePage.Shapes
If shp.Type = 2 Then
For Each subshp In shp.GroupItems
If subshp.CellExistsU(propName, 0) Then
If subshp.CellsU(propName).ResultIU = id Then
Set getShape = subshp
Exit For
End If
End If
Next subshp
End If
If shp.CellExistsU(propName, 0) Then
If shp.CellsU(propName).ResultIU = id Then
Set getShape = shp
Exit For
End If
End If
Next
End Function
我认为我遍历子形状的方式有问题。 任何帮助表示赞赏。
【问题讨论】:
-
奇怪,在我这边我没有问题和分歧。你能分享你定义连接器形状的代码吗?连接目标和src形状?
-
PS:连接目标和src你想使用连接器还是线?
-
我的连接器本身就是一个形状。我用一条简单的曲线创建了一个新的大师。我认为我的问题一定出在其中一个 for 循环中,因为当我在执行期间查看变量时,应该保持组中形状的变量仍然是“Nothing”,因此胶水方法失败。
-
Visio 有一种名为“连接器”的特殊形状,请在this article 中阅读有关连接器的更多信息。我的代码适用于连接器
-
另外,从代码的外观来看,您会与 Excel(和其他 Office)形状混淆。 Office 的其余部分具有与 Visio 不同的结构和对象模型。 (请注意,您在上一个问题中的 wiseowl 链接也是基于 Excel 的)。所以不是
foreach subshp in shp.GroupItems,应该是...In shp.Shapes