Visio VBA试图获取容器和成员形状的列表

问题描述 投票:0回答:1

背景:我有一些代码贯穿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, 0, 1), 0)
shapeContainer = containerArr(x, 1)
arrays vba visio
1个回答
0
投票

我认为您正在寻找的是Shape.MemberOfContainers,它返回一个形状是其成员的容器的数组。

您也可以查看这篇涉及相同问题的帖子:

Shape.MemberOfContainers

[我还将链接到大卫·帕克(David Parker)的文章,该文章在跨功能流程图的上下文中涵盖了容器,它充分利用了容器和列表:

Visio: How to get the shapes that are contained in one shape?

© www.soinside.com 2019 - 2024. All rights reserved.