Visio VBA正在尝试获取容器和成员形状的列表



背景:我有一些代码可以运行Visio页面并返回所有形状。这些形状中的许多都在容器中,所以我想知道一个形状属于哪个容器。

原始方法:我希望使用shape.ContaineringShape属性检索每个形状的"父"容器(我只需要一个级别的容器,容器中没有容器(,但这只为每个形状返回"0"。

如果有人能解决我最初如何获得容器的问题,那将是最优雅的。但由于我无法做到这一点,我正在尝试以下替代方案,这也是一个障碍。

当前方法:我能够获得页面上所有容器的列表,现在我想为每个容器提取成员形状。它没有那么干净,但它可以让我交叉参考形状并获得它们所属的容器。

问题:当尝试创建一个列0为容器名称、列1为成员形状的数组时,我收到"错误13类型不匹配"。

' Create array of containers and member shapes
Dim arr() As Long
Dim vsoMemberShape As Shape
Dim vsoContainerShape As Shape
Dim containerArr() As Long
Dim rows As Integer
Dim i As Integer
For Each ContainerID In vsoPage.GetContainers(visContainerIncludeNested)
Set vsoContainerShape = vsoPage.Shapes.ItemFromID(ContainerID)
arr = vsoContainerShape.ContainerProperties.GetMemberShapes(1)
rows = UBound(arr)
ReDim containerArr(0 To rows, 0 To 1)
For i = 0 To UBound(arr)
Set memberShape = vsoPage.Shapes.ItemFromID(arr(i))
containerArr(i, 0) = vsoContainerShape.NameU
containerArr(i, 1) = vsoMemberShape.NameU
Next
Next
' The following code is in a For loop, not shown
' shapeToName is what I want to compare to the member shapes in the container 
' array defined above, and then retrieve the corresponding container
' This is where the error is popping up
shapeToName = CStr(vsoShapeTo.Name)
Dim x As Integer
x = Application.Match(shapeToName, Application.Index(containerArr, 0, 1), 0)
shapeContainer = containerArr(x, 1)

我想您要找的是Shape.MemberOfContainers,它返回一个形状所属的容器数组。

你也可以看看这篇文章,它涵盖了相同的问题:

Visio:如何获取包含在一个形状中的形状?

我还将添加一个链接到David Parker的一篇文章,该文章在跨功能流程图的背景下介绍容器,该流程图很好地利用了容器和列表:

https://bvisual.net/2009/09/07/visio-2010-containment-and-cross-functional-flowcharts/

最新更新