且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VBA对于每个-循环顺序

更新时间:2023-11-07 13:38:46

在OP澄清了他需要循环从最高到最低的形状后进行编辑

edited after OP's clarification about his need of looping through shapes from the highest on the lowest

您可以使用 SortedList 对象使用 Shape Top 属性作为 SortedList 键,而 Shape 对象本身作为其对应值:

you can use SortedList object use Shape Top property as the SortedList key and the Shape object itself as its corresponding value:

Sub Main()
    Dim shp As Shape
    Dim j As Long

    With CreateObject("System.Collections.SortedList")
        For Each shp In slide.Shapes
            .Add shp.Top, shp
        Next

        For j = 0 To .Count - 1 'list shapes from the highest to the lowest
            MsgBox .GetByIndex(j).Name & " - " & .getkey(j)
        Next

    End With
End Sub