、あなたが形にそれを割り当てたい:いくつかの回避策の後
Sub FindOle()
Dim shp As Shape
Dim allShapes As Shape
Dim c As Long
For Each shp In ActiveDocument.Shapes
Debug.Print shp.Name
Set allShapes = shp
Next shp
Debug.Print allShapes.Name
End Sub
、ここGroupShapes
クラスを使用するには良い方法です:空のWord文書に
Option Explicit
Sub FindOle()
Dim shp As Shape
Dim allShapes As GroupShapes
Dim cnt As Long
With ActiveDocument.Shapes
.AddShape(msoShapeIsoscelesTriangle, 10, 10, 100, 100).Name = "shp1"
.AddShape(msoShapeIsoscelesTriangle, 150, 10, 100, 100).Name = "shp2"
.AddShape(msoShapeIsoscelesTriangle, 300, 10, 100, 100).Name = "shp3"
'assign the shapes to a group
With .Range(Array("shp1", "shp2", "shp3")).Group
Set allShapes = .GroupItems
End With
'format the first and the third shape, prints the name of the shape:
For cnt = 1 To allShapes.Count
Debug.Print allShapes.Item(cnt).Name
If cnt/2 <> 1 Then
allShapes.Item(cnt).Fill.PresetTextured msoTextureGreenMarble
End If
Next cnt
'print the name of the shapes in a different way:
For cnt = 1 To allShapes.Count
Debug.Print .Range(Array("shp1", "shp2", "shp3"))(cnt).Name
Next cnt
End With
End Sub
それがグループに割り当てとallShapes
変数を介して、または.Range(Array())
を介してそれらにアクセスし、3つの形状を作成します。
GroupShapes MSDN
おかげ@Vityata、私は簡単にActiveDocument.Shapesオブジェクトとその内部GroupItemsアクセスすることができます。主な問題は、アクセス違反をスローするActiveDocument.InlineShapes.GroupItemです – fluffybunny