
Table of Contents
Problem Statement
In real world scenario, you must have felt or faced this scenario. You have one presentation with N number of slides. Now, you want to break the presentation file into multiple slides with say N-3, N-10 slides or whatever.
Example, if I have a presentation with country wise revenue in each slide, say, 10 countries. Now, I want to seggregate this slide into each slide containing 1 slide. Now, to create 10 different presentation from 1 presentation can be time consuming and hectic.
Exploring Solution via VBA
To tackle this challenge, you’re considering dividing the presentation into multiple smaller segments. One approach would involve manually creating multiple copies of the original presentation, opening each copy individually, removing unwanted slides, and saving them accordingly.
Alternatively, you have the option to leverage the power of VBA (Visual Basic for Applications) to automate this task effortlessly. By exploring this route, you can delegate the job to VBA, allowing it to split the presentation into smaller components automatically. Read further to discover the benefits and simplicity offered by this automated solution…
This VBA routine will ask how many slides you want per presentation, then will split your presentation into several sub-presentations, each with the number of slides you requested, each named to reflect the slide numbers it contains.
For example, if your original file MyReport.PPT contains 55 slides and you ask SplitFile to split it to 25 slides per file, you’ll get:
- MyReport_1-25.PPT
- MyReport_26-50.PPT
- MyReport_51-55.PPT
The new files will be saved to the same folder as the original file. The original file will not be altered.
Sub SplitFile()
Dim lSlidesPerFile As Long
Dim lTotalSlides As Long
Dim oSourcePres As Presentation
Dim otargetPres As Presentation
Dim sFolder As String
Dim sExt As String
Dim sBaseName As String
Dim lCounter As Long
Dim lPresentationsCount As Long ' how many will we split it into
Dim x As Long
Dim lWindowStart As Long
Dim lWindowEnd As Long
Dim sSplitPresName As String
On Error GoTo ErrorHandler
Set oSourcePres = ActivePresentation
If Not oSourcePres.Saved Then
MsgBox "Please save your presentation then try again"
Exit Sub
End If
lSlidesPerFile = CLng(InputBox("How many slides per file?", "Split Presentation"))
lTotalSlides = oSourcePres.Slides.Count
sFolder = ActivePresentation.Path & "\"
sExt = Mid$(ActivePresentation.Name, InStr(ActivePresentation.Name, ".") + 1)
sBaseName = Mid$(ActivePresentation.Name, 1, InStr(ActivePresentation.Name, ".") - 1)
If (lTotalSlides / lSlidesPerFile) - (lTotalSlides \ lSlidesPerFile) > 0 Then
lPresentationsCount = lTotalSlides \ lSlidesPerFile + 1
Else
lPresentationsCount = lTotalSlides \ lSlidesPerFile
End If
If Not lTotalSlides > lSlidesPerFile Then
MsgBox "There are fewer than " & CStr(lSlidesPerFile) & " slides in this presentation."
Exit Sub
End If
For lCounter = 1 To lPresentationsCount
' which slides will we leave in the presentation?
lWindowEnd = lSlidesPerFile * lCounter
If lWindowEnd > oSourcePres.Slides.Count Then
' odd number of leftover slides in last presentation
lWindowEnd = oSourcePres.Slides.Count
lWindowStart = ((oSourcePres.Slides.Count \ lSlidesPerFile) * lSlidesPerFile) + 1
Else
lWindowStart = lWindowEnd - lSlidesPerFile + 1
End If
' Make a copy of the presentation and open it
sSplitPresName = sFolder & sBaseName & _
"_" & CStr(lWindowStart) & "-" & CStr(lWindowEnd) & "." & sExt
oSourcePres.SaveCopyAs sSplitPresName, ppSaveAsDefault
Set otargetPres = Presentations.Open(sSplitPresName, , , True)
With otargetPres
For x = .Slides.Count To lWindowEnd + 1 Step -1
.Slides(x).Delete
Next
For x = lWindowStart - 1 To 1 Step -1
.Slides(x).Delete
Next
.Save
.Close
End With
Next ' lpresentationscount
NormalExit:
Exit Sub
ErrorHandler:
MsgBox "Error encountered"
Resume NormalExit
End Sub
Video Tutorial to use VBA code
You can check out the tutorial video below to learn how to use the VBA code provided above in this blogpost.
Conclusion
Now, this tutorial has made you understand how to split a presentation file into multiple presentations and make our work easier. Write us at [email protected] if you have any query. Don’t forget to subscribe us on Youtube.