Powerpoint VBA:从第二张幻灯片执行

时间:2015-04-23 09:43:11

标签: vba powerpoint powerpoint-vba

美好的一天,

我已经有了这段代码来修改所有幻灯片上每个形状的大小和位置,但是希望程序只能从幻灯片2开始。

Sub SlideLoop()
    Dim osld As Slide
    Dim oSh As Shape

    For Each osld In ActivePresentation.Slides
        ' check each shape on the slide
        ' is it an image or whatever you're looking for?
        For Each oSh In osld.Shapes
            With oSh
                If .Type = msoLinkedPicture _
                Or .Type = msoPicture Then

                ' position it to taste
                .Left = 30
                .Top = 100
                .Height = 750
                .Width = 680

                ' centering/resizing gets trickier
                ' but is still possible.
                ' Exercise for the reader?
                ' Hint:
                ' ActivePresentation.PageSetup.SlideWidth and .SlideHeight
                ' tells you the width and height of the slide
                '
                ' All values are in Points (72 to the inch)

                End If
            End With
        Next    ' Shape
    Next osld   ' Slide

End Sub}

我需要改变什么?

2 个答案:

答案 0 :(得分:0)

检查幻灯片的SlideIndex属性 - 如果是1,则跳到下一张幻灯片。

For Each osld In ActivePresentation.Slides循环内,添加一个if语句:

If osld.SlideIndex > 1 Then
    'Your code...
    For Each oSh In osld.Shapes
    ...
    Next    ' Shape
End If

答案 1 :(得分:0)

Olle是对的。或者另一种方法,我在 BOLD

中的更改
Sub SlideLoop()
    Dim osld As Slide
    Dim oSh As Shape

Dim x为Long

'For Each osld In ActivePresentation.Slides

对于x = 2到ActivePresentation.Slides.Count

设置oSld = ActivePresentation.Slides(x)

    ' check each shape on the slide
    ' is it an image or whatever you're looking for?
    For Each oSh In osld.Shapes
        With oSh
            If .Type = msoLinkedPicture _
            Or .Type = msoPicture Then

            ' position it to taste
            .Left = 30
            .Top = 100
            .Height = 750
            .Width = 680

            ' centering/resizing gets trickier
            ' but is still possible.
            ' Exercise for the reader?
            ' Hint:
            ' ActivePresentation.PageSetup.SlideWidth and .SlideHeight
            ' tells you the width and height of the slide
            '
            ' All values are in Points (72 to the inch)

            End If
        End With
    Next    ' Shape
Next osld   ' Slide

End Sub