我在文档中创建了一个分组形状:
Dim doc As Word.Document
Set doc = Documents("dlr-overview.docx")
Dim firstShape As Word.Shape
Set firstShape = doc.Shapes(1)
AutoShapeType
onfirstShape
返回-2
,或msoShapeMixed
;和firstShape.GroupItems.Count
返回25
:
Debug.Print firstShape.AutoShapeType
Debug.Print firstShape.GroupItems.Count
我可以在firstShape.GroupItems
的形状上迭代,而不投射到Shape
。TypeName
为每个元素返回"Shape"
,AutoShapeType
属性返回5
或msoShapeRoundedRectangle
:
Dim x As Variant
For Each x In firstShape.GroupItems
Debug.Print TypeName(x)
Debug.Print x.AutoShapeType
Next
但是当我尝试将每个元素转换为Shape
时,我得到类型不匹配关于For Each
的第一次迭代:
Dim subshape As Shape
For Each subshape In firstShape.GroupItems
Debug.Print subshape.Left
Next
如何从分组形状中提取有关单个形状的信息?
似乎不可能使用形状进行枚举变量GroupShapes从Shape返回的对象。GroupItems. 在迭代中也会出现以下错误:
Dim shapes As GroupShapes
Set shapes = firstShape.GroupItems
Dim shp As Shape
For Each shp In shapes
Debug.Print shp.Name
Next
显然返回的元素不是Word。对象,即使TypeName函数返回这些对象的"Shape"
。
Dim i As Integer
For i = 1 To firstShape.GroupItems.Count
Dim shp As Shape
Set shp = firstShape.GroupItems(i)
Debug.Print shp.Name
Next