在VBA中,可以遍历形状。例如:
For Each shp In slide.Shapes
shp.top=0
Next
问题是,哪个参数用于确定循环的顺序以及如何设置此参数?
答案 0 :(得分:1)
您可以使用SortedList
对象使用Shape
Top
属性作为SortedList
键,Shape
对象本身作为其对应值:
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
答案 1 :(得分:0)
我在MicroSoft网站上找到了答案:
Shape.ZOrderPosition Property (PowerPoint)
该网站说“ z形顺序中的形状位置对应于形状集合中形状的索引编号。”。
然后我做了一个简短的排序程序,根据形状的.top参数设置z顺序位置:
For i = 2 To sld.Shapes.Count
If sld.Shapes(i).Top < sld.Shapes(i - 1).Top _
and sld.Shapes(i).ZOrderPosition > sld.Shapes(i - 1).ZOrderPosition Then_
sld.Shapes(i).ZOrder msoSendBackward
Next i