将幻灯片从头到尾移动

时间:2020-01-14 09:01:20

标签: vba powerpoint

我有一个宏,可以在PowerPoint演示文稿的部分开头创建一个新幻灯片。

是否有替换.MoveToSectionStart的方法可以将幻灯片移到末尾?

该方法位于名为Sub AddCustomSlide()的Sub的末尾。

Private Function GetSectionNumber( _
        ByVal sectionName As String, _
        Optional ParentPresentation As Presentation = Nothing) As Long

    If ParentPresentation Is Nothing Then
        Set ParentPresentation = ActivePresentation
    End If

    GetSectionNumber = -1
    With ParentPresentation.SectionProperties
        Dim i As Long
        For i = 1 To .Count
            If .Name(i) = sectionName Then
                GetSectionNumber = i
                Exit Function
            End If
        Next i
    End With
End Function

Public Function GetLayout( _
    LayoutName As String, _
    Optional ParentPresentation As Presentation = Nothing) As CustomLayout

    If ParentPresentation Is Nothing Then
        Set ParentPresentation = ActivePresentation
    End If

    Dim oLayout As CustomLayout
    For Each oLayout In ParentPresentation.SlideMaster.CustomLayouts
        If oLayout.Name = LayoutName Then
            Set GetLayout = oLayout
            Exit For
        End If
    Next
End Function

Sub AddCustomSlide()

    Dim oSlides As Slides, oSlide As Slide
    Dim Shp As Shape
    Dim Sld As Slide

    Set oSlides = ActivePresentation.Slides
    Set oSlide = oSlides.AddSlide(oSlides.Count - 2, GetLayout("Processwindow"))
    oSlide.MoveToSectionStart GetSectionNumber("Main Process")

End Sub

1 个答案:

答案 0 :(得分:1)

对不起,没有这样的方法。这是在最后插入一个的方法:

Sub AddCustomSlide()
    Dim oSlides As Slides, oSlide As Slide
    Dim Shp As Shape
    Dim Sld As Slide
    Dim SecNum As Integer, SlideCount As Integer, FirstSecSlide As Integer

    Set oSlides = ActivePresentation.Slides
    Set oSlide = oSlides.AddSlide(oSlides.Count - 2, GetLayout("Processwindow"))
    SecNum = GetSectionNumber("Main Process")
    With ActivePresentation.SectionProperties
        SlideCount = .SlidesCount(SecNum)
        FirstSecSlide = .FirstSlide(SecNum)
    End With
    oSlide.MoveTo toPos:=FirstSecSlide + SlideCount - 1
End Sub