2017-12-18 12 views
2

Word 문서에서 ole 개체를 찾으려고하는데 InlineShapes(1).GroupItems 인 것 같습니다. 그룹 항목에 액세스 할 수 없으므로 오류가 발생합니다.이 멤버는 그룹 VBA Word 문서에 대해서만 액세스 할 수 있습니다.

Sub findOle() 
    Dim shp As GroupShapes 
    Dim c As Integer 
    Set shp = ActiveDocument.InlineShapes(1).GroupItems 
End Sub 

이 회원은 그룹

내가 ActiveDocument.Shapes(1).GroupItems.Item(1)에 액세스 할 수 있어요하지만에 대한 액세스 할 수 없습니다 InlineShapes.

어떤 제안?

답변

1

만 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

+0

감사 @Vityata, 난 쉽게 ActiveDocument.Shapes 개체와 그 안에 GroupItems에 액세스 할 수 있습니다. 주요 문제는 액세스 위반을 throw하는 ActiveDocument.InlineShapes.GroupItem 때문입니다. – fluffybunny