VBA对于每个-循环顺序 [英] VBA For each - loop order
本文介绍了VBA对于每个-循环顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VBA中,可以遍历形状。例如:
In VBA, it's possible to loop through shapes. For example:
For Each shp In slide.Shapes
shp.top=0
Next
问题是,使用哪个参数确定循环的顺序以及如何设置该参数?
The question is, which parameter is being used to determine the order of the loop and how can this parameter be set?
推荐答案
在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
这篇关于VBA对于每个-循环顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文