Steffa91
Steffa91

Reputation: 17

Moving slide from beginning to section end

I have a macro that creates a new slide at the beginning of a section in my PowerPoint presentation.

Is there a method to replace .MoveToSectionStart that would move the slide to the end?

The method is found in the Sub at the end called Sub AddCustomSlide().

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

Upvotes: 0

Views: 1326

Answers (1)

John Korchok
John Korchok

Reputation: 4913

Sorry, there's no such method. Here's how to insert one at the end:

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

Upvotes: 2

Related Questions