在powerpoint中使用vba将两个形状合并为联合

时间:2017-09-03 12:55:47

标签: vba powerpoint powerpoint-vba

我正在尝试使用union属性将两个相同的形状合并为一个。在编译代码时,它显示对象'commandbar'的方法'executemso'失败。我是vba的新手,所以如果有人帮我解决这个问题会很棒。

Sub ShapesUnion()

    Dim sld As Slide
    Dim shp As Shape

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

            If shp.Fill.Type = msoFillSolid Then
            With shp.Duplicate
                .Left = shp.Left
                .Top = shp.Top
            End With
            End If
            shp.Select
            CommandBars.ExecuteMso ("ShapesUnion")
        Next
    Next

End Sub

1 个答案:

答案 0 :(得分:2)

您可以使用MergeShapes方法实现此目的:

Dim shp1 As Shape
Dim shp2 As Shape

Set shp1 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeOval, 100, 100, 50, 50)
Set shp2 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapePie, 100, 100, 50, 50)
Call ActiveWindow.Selection.SlideRange(1).Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition)).MergeShapes(msoMergeCombine)