如何用vba设置ppt幻灯片中的图片尺寸与幻灯片的尺寸一样全覆盖?

有时候,我们希望在ppt中每个幻灯片中都插入一个图片,然后让图片覆盖整个幻灯片大小,相当于一个幻灯片就是一个图片。
在VBA中,可以用ppt的PageSetup对象的SlideWidth和SlideHeight属性先读取每页幻灯片的宽度和高度。
然后将图片Shape对象的宽度和高度设置为PageSetup对象的SlideWidth和SlideHeight属性值。
代码如下:

Sub QQ1722187970()
    Dim oPPT As PowerPoint.Presentation
    Dim oSlide  As Slide
    Set oPPT = PowerPoint.ActivePresentation
    Dim oSP As Shape
    Dim oSPRange As ShapeRange
    Dim arr()
    With oPPT
        Debug.Print .PageSetup.SlideHeight
        Debug.Print .PageSetup.SlideWidth
        For Each oSlide In .Slides
            With oSlide
              For Each oSP In .Shapes
                    With oSP
                        '不锁定纵横比,这句是关键,没有这句无法调整大小
                        .LockAspectRatio = msoFalse
                        .Left = 0
                        .Top = 0
                        .Width = oPPT.PageSetup.SlideWidth
                        .Height = oPPT.PageSetup.SlideHeight
                    End With
              Next
            End With
        Next
    End With
End Sub

       

发表评论