Как я могу выбрать диапазон слайдов в Powerpoint (VBA) - PullRequest
0 голосов
/ 15 октября 2018

Я редактирую код 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

Я получил ошибку на компиляторе.Может ли кто-нибудь помочь мне, отредактировав это или другим способом?примечание *: я начинающий с VBa:)

1 Ответ

0 голосов
/ 15 октября 2018

Я внес некоторые изменения, чтобы он работал, и попытался сохранить базовый кадр кода без изменений.Вы можете в дальнейшем развивать в соответствии с вашими потребностями (для изменения объектов и их свойств) .Пожалуйста, всегда используйте автозаполнение при наборе кода.Это помогает кому-то придерживаться правильных свойств или методов любого объекта.

    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
...