Access/VBA Library

SplitSection

Copies the slides within section at SectionIndex in the file Filename to a new presentation and returns a reference to the new presentation. The name of the new file created is the name of the given presentation followed by the sectionindex and sectionname.

Syntax

SplitSection( Filename, SectionIndex )
Parameters
Name Type Description
Filename String Required. Source from which the slides has to be copied.
SectionIndex Long Required. The index of section.
Return value

Presentation : Reference to the new presentation.

Code
Function SplitSection(Filename As String, SectionIndex As Long) As Presentation
    Dim Index As Long
    Dim CurrentPresentation As Presentation
    Dim SectionName As String
    Dim NewFilename As String
    
    With Application_
        '
        ' Open the presentation
        '
        Set CurrentPresentation = .Presentations.Open(Filename, msoFalse, msoTrue, msoFalse)
        
        With CurrentPresentation
            '
            ' Remove all sections and slides except
            '
            With .SectionProperties
                
                For Index = .Count To 1 Step -1
                    If Index <> SectionIndex Then
                        .Delete Index, True
                    Else
                        SectionName = .name(Index)
                    End If
                Next Index
            
            End With
            
            RemoveUnusedLayouts CurrentPresentation
            
            With FSO
                NewFilename = .GetParentFolderName(Filename) & "\" & _
                              .GetBaseName(Filename) & "_" & _
                              Format(SectionIndex, "000") & "_" & _
                              SectionName & ".pptx"
            End With
            
            .SaveAs NewFilename, ppSaveAsOpenXMLPresentation
        End With
    End With

    Set SplitSection = CurrentPresentation
End Function

PowerPointtag:PowerPoint

Remarks

  • The returned presentation will be unvisible!.

See also

  • RemoveUnusedLayouts