2017-12-18 62 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.

任意の提案と?あなたが唯一のWordで図形の一つのグループを持っている場合は、これがうまくいく

答えて

1

、あなたが形にそれを割り当てたい:いくつかの回避策の後

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アクセスすることができます。主な問題は、アクセス違反をスローするActiveDocument.InlineShapes.GroupItemです – fluffybunny

関連する問題