如何用vba实现ppt幻灯片中层叠图形的置于顶层或置于底层命令?

如下图所示的ppt幻灯片中有12个矩形,其中6个矩形被其中6个矩形层叠覆盖在底层。

如果要实现将某个图形置于顶层或置于底层,从而让它显示在层叠图片的上面或者隐藏在层叠图片的下面的效果,可以使用Shape对象的ZOrder方法将指定的图形置于顶层或者置于底层。

代码如下:

Sub QQ1722187970()
    Dim oPPT As Presentation
    Dim oSlide As Slide
    Dim oCL As CustomLayout
    Dim oP As Shape
    '当前ppt演示文稿
    Set oPPT = PowerPoint.ActivePresentation
    With oPPT
        '遍历每一个幻灯片
        For Each oSlide In .Slides
            i = 1
            With oSlide
               Set oP = .Shapes("矩形1")
               '置于顶层
               oP.ZOrder (msoBringToFront)
                Set oP = .Shapes("矩形11")
                '置于底层
               oP.ZOrder (msoSendToBack)
            End With
        Next
    End With
End Sub

代码运行后的效果如下图所示:

原来的矩形7被矩形1覆盖了,原来的矩形11被矩形5覆盖了。

       

发表评论