만 Word에서 모양의 한 그룹이있는 경우 모양에 할당 할 때,이, 일 것이다 : 어떤 문제를 해결 한 후
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에 액세스 할 수 있습니다. 주요 문제는 액세스 위반을 throw하는 ActiveDocument.InlineShapes.GroupItem 때문입니다. – fluffybunny