背景:我有一些代码贯穿Visio页面并返回所有形状。这些形状中有很多都在容器中,所以我想知道形状属于哪个容器。
原始方法:我希望使用Shape.ContainingShape属性来检索每种形状的“父”容器(我只需要一个容器级别,容器内没有容器),但是每种形状只返回“ 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,1),0)
shapeContainer = containerArr(x,1)