Buc*_*son 1 iteration excel vba shapes
下面的代码不考虑分组形状。有没有解决的办法?
Sub LoopThruShapes()
Dim sh As Shape
i=1
For Each sh In ActiveSheet.Shapes
Cells(i, 1).value = sh.name
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
来源:http : //www.java2s.com/Code/VBA-Excel-Access-Word/Excel/LoopingthroughaCollectionofShapes.htm
您可以尝试以下代码:
Sub test()
EnumShapes ActiveSheet.shapes
End Sub
Function EnumShapes(shps As Shapes)
Dim shp As Shape
Dim subshp As Shape
For Each shp In shps
Debug.Print shp.Name
If shp.Type = msoGroup Then
For Each subshp In shp.GroupItems
Debug.Print Space(2) + subshp.Name
Next subshp
End If
Next shp
End Function
Run Code Online (Sandbox Code Playgroud)
如果分组的形状本身是一个组,则上面的代码不会标识子组,因为Excel会平铺GroupItems集合中的形状,但会枚举所有形状(无论其深度如何)。
您将获得如下输出:
Rectangle 1
Group 4
Rectangle 2
Rectangle 3
Group 12
Rectangle 6
Rectangle 7
Rectangle 9
Rectangle 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4232 次 |
| 最近记录: |