我如何在Powerpoint(VBA)中选择一系列幻灯片

时间:2018-10-15 11:46:58

标签: vba vbscript powerpoint

我编辑VBa代码以裁剪有功功率点或特定幻灯片中的所有图片,但是当我要指定范围(例如从幻灯片8到40)时,我尝试如下:

    Sub Auto_pic_crop()
    Dim oshp As Shape
    Dim osld As Slide
    Dim Istart As Integer
    Dim Iend As Integer
    Istart = ActivePresentation.Slides.Range(Array(8))
    Iend = ActivePresentation.Slides.Range(Array(40))
    For Each osld In ActivePresentation.Slides
    Do While (ActivePresentation.Slides.Range() > Istart) And (ActivePresentation.Slides.Range() < Iend)
    For Each oshp In osld.Shapes
    If oshp.Type = msoPicture Then
    oshp.Width = in2Points(9.77)
    oshp.Height = in2Points(4.47)
    With oshp.PictureFormat
    .Crop.PictureWidth = in2Points(9.69)
    .Crop.PictureHeight = in2Points(5.83)
    .Crop.ShapeWidth = in2Points(9.64)
    .Crop.ShapeHeight = in2Points(4.49)
    .Crop.ShapeLeft = in2Points(0.2)
    .Crop.ShapeTop = in2Points(0.77)
    .Crop.PictureOffsetX = in2Points(0)
    .Crop.PictureOffsetY = in2Points(-0.12)
    End With
    End If
    If oshp.Type = msoPlaceholder Then
    If oshp.PlaceholderFormat.ContainedType = msoPicture Then
    End If
    End If
    Next oshp
    Loop
    Next osld
    End Sub

    Function in2Points(inVal As Single) As Single
    in2Points = inVal * 72
    End Function

我在编译器上遇到错误。 是否有人可以通过编辑此方法或其他方法来帮助我? note *:我是VBa的初学者:)

1 个答案:

答案 0 :(得分:0)

我进行了一些更改以使其运行,并尝试保持代码的基本框架完整。您可以根据需要进一步开发(以修改对象及其属性)。请始终在键入代码时使用自动完成功能。它可以帮助某人坚持正确的对象属性或方法。

    Sub Auto_pic_crop()

    Dim Shp As shape
    Dim Sld As Slide
    Dim Istart As Integer
    Dim Iend As Integer
        'Istart = ActivePresentation.Slides.Range(Array(8))
        'Iend = ActivePresentation.Slides.Range(Array(40))
        'Simply loop through slode nos I could not Understand Range(Array()) part
        Istart = 2   'change according to yuor need
        Iend = 4     'change according to yuor need

        For X = Istart To Iend
        Set Sld = ActivePresentation.Slides(X)

            For Each Shp In Sld.Shapes
            If Shp.Type = msoPicture Then
            'Shp.Width = in2Points(9.77)
            'Shp.Height = in2Points(4.47)
                With Shp.PictureFormat
                ' I could only think about four type of crop property and
                .CropLeft = in2Points(0.2)
                .CropTop = in2Points(0.77)
                .CropRight = in2Points(0.2)
                .CropBottom = in2Points(0.2)
                End With
            End If

            'No action found attached to the Code below
            If Shp.Type = msoPlaceholder Then
            If Shp.PlaceholderFormat.ContainedType = msoPicture Then
            End If
            End If

            Next Shp
        Next X
        End Sub

Function in2Points(inVal As Single) As Single
    in2Points = inVal * 72
    End Function