PowerPoint VBA: Export Slides to Single Slide Presentations

Created: Wednesday, October 16, 2019, posted by Geetesh Bajaj at 9:30 am

Updated: at



One of our most popular posts is one where you learn how you can export all the slides in your presentation to single-slide PowerPoint presentations. Although the interface for this process uses the SharePoint libary options, many more people used this feature to export single-slide presentations, without worrying about anything to do with SharePoint. Did you notice used rather than use in the previous sentence? Yes, this feature is now deprecated! If you have an older installation of PowerPoint that is not updated, this may still work for you. Otherwise, this amazing feature is dead.

Understandably, many PowerPoint users are unhappy because it’s a real pain to export hundred of slides as individual slide files. Thankfully, our good friend, Jamie Garroch from BrightCarbon has written some VBA code that will help you revive this option!

First you need to know how you can run VBA scripts in PowerPoint — then use this code. Explore the code a bit though. Also, do you see the “Option Explicit” line at the beginning of the code below? If your PowerPoint file has an existing module that already includes this line atop the code, you don’t need the first line again, and you can leave out this line from the top.

Option Explicit
' =======================================================================
' PowerPoint VBA Macro
' =======================================================================
' Purpose: Takes each non-hidden slide in a presentation and creates a
'          single-slide presentation in the same folder as the source
'          deck with the file name suffixed with the slide number.
' Example: If a three-slide active presentation is called myDeck.pptx the
'          following presentation files are created:
'             myDeck [slide 1].pptx
'             myDeck [slide 2].pptx
'             myDeck [slide 3].pptx
' Author:  Jamie Garroch of BrightCarbon
' Date:    05MAR2019
' =======================================================================
Sub ExportSlidesAsPresentations()
  Dim oSld As Slide           ' Reference to a slide object
  Dim tPath As String         ' Path of the active presentation
  Dim tFileName As String     ' Filename for the output presentation
  Dim arrSR() As Variant      ' Array of slides to be deleted
  Dim lIdx As Long            ' Slide index counter
  Dim lCount As Long          ' Slides array dimension
  Dim lSldIdx As Long         ' Current slide index
  Dim lVisibleSlides As Long  ' Total number of visible slides to export
 
  On Error GoTo errorhandler
 
  For Each oSld In ActivePresentation.Slides
    If Not oSld.SlideShowTransition.Hidden Then lVisibleSlides = lVisibleSlides + 1
  Next
 
  If MsgBox("Depending on the number of visible slides to export and the size " & _
    "of your presentation, this might take some time." & vbCrLf & vbCrLf & "Continue?", _
    vbYesNo + vbQuestion, _
    "Export " & lVisibleSlides & " Visible Slides to Presentations") = vbNo Then Exit Sub
 
  With ActivePresentation
    tPath = ActivePresentation.Path
 
    ' Export each slide as a presentation by deleting all other slides
    ' and the restore the slides using ctrl+z
    For Each oSld In .Slides
      If Not oSld.SlideShowTransition.Hidden Then
        lSldIdx = oSld.SlideIndex
        Erase arrSR
        lCount = 0
 
        ' Get an array of all slides in the presentation except this one
        For lIdx = 1 To .Slides.Count
          If Not oSld Is .Slides(lIdx) Then
            ReDim Preserve arrSR(lCount)
            arrSR(lCount) = lIdx
            lCount = lCount + 1
          End If
        Next
 
        ' Select and delete all slides except this one
        If ActiveWindow.ViewType = ppViewNormal Then ActiveWindow.Panes(1).Activate
        .Slides.Range(arrSR).Select
        ActiveWindow.Selection.Delete
        DoEvents
 
        ' Build a unique filename and save a coy of the now single-slide presentation
        tFileName = Left(.Name, InStrRev(.Name, ".") - 1) & " [slide " & lSldIdx & "].pptx"
        .SaveCopyAs tPath & "\" & tFileName, ppSaveAsOpenXMLPresentation
 
        ' Undo the slide deletion to recover all slides
        CommandBars.ExecuteMso "Undo"
        DoEvents
      End If
    Next
 
  End With
 
  ' Give feedback to the user
  MsgBox lVisibleSlides & " slide(s) exported to " & tPath, _
         vbQuestion + vbOKOnly, "BrightCarbon - Export Complete"
 
  On Error GoTo 0
 
  Exit Sub
 
errorhandler:
  Debug.Print Err, Err.Description
  Resume Next
End Sub

Now follow these steps:

  1. Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint window.
  2. Before you proceed further, it’s a great idea to save your file. Be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then, of course, the code to export single-slide PowerPoint presentations will not work!
  3. See our PowerPoint File Formats page to learn about these file formats.
  4. Then open or switch to the presentation which has multiple slides and run the macro.
  5. To do so, press the Alt + F8 shortcut key. In the Macro dialog box that appears, for Macro in: choose All open presentations, as shown highlighted in red within Figure 1, below.
  6. Macro dialog box
    Figure 1: Macro dialog box
  7. Now click the ExportSlidesAsPresentations Macro name (highlighted in blue), and then click the Run button, highlighted in green.

We tested this code using PowerPoint 365 for Windows.

We used a sample presentation, shown in the folder in Figure 2.

Single PowerPoint file
Figure 2: Single PowerPoint file

This presentation file has 11 slides, as can be seen in Figure 3, below.

Eleven PowerPoint slides
Figure 3: Eleven PowerPoint slides

We ran the macro, as explained previously in this post, and saw the message box that you can see in Figure 4, below. We clicked the Yes button.

Export slides
Figure 4: Export slides

Soon, we found another message that indicates the slides were successfully exported, as can be seen in Figure 5, below.

Export complete
Figure 5: Export complete

Sure enough, the folder containing the presentation now had 11 more PowerPoint files in addition to the original file (see Figure 6). These 11 presentations were all single slide presentations.

Exported slides
Figure 6: Exported slides

Do note though that this code works best in Normal view. Don’t try in Slide Sorter view.

Related Content: Export All Slides to Single Slide PowerPoint Presentations

You May Also Like: Jamie’s Pattern Fill Transparency Add-in for PowerPoint | PowerPoint 2013 for Developers: Conversation with Jamie Garroch


Do note that Jamie recommends the BrightSlide add-in for PowerPoint that provides a couple of variations of this feature, as can be seen in the screenshot below.

BrightSlide Export options


Jamie Garroch
    
Jamie Garroch is a Technical Consultant at BrightCarbon, the specialist presentation and eLearning agency.

He develops PowerPoint automation solutions and add-ins that enable presentation authors to work smarter.

He also trains people to present more effectively using visuals and animated scenes that explain and reinforce key messages, which is supported by free resources and tips at their site.

Filed Under: Programming
Tagged as: , , ,

No Comments

Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.

Plagiarism will be detected by Copyscape

© 2000-2019, Geetesh Bajaj - All rights reserved.

since November 02, 2000