This documentation is archived and is not being maintained.

Programmatically Publishing Slides in PowerPoint 2010

Office 2010

Office Quick Note banner

Handy Programming Tips for Microsoft PowerPoint 2010: Learn how to publish some or all of the slides in Microsoft PowerPoint 2010.

Last modified: May 19, 2011

Applies to: Office 2010 | PowerPoint 2010 | VBA

In this article
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Run the Code
Next Steps

Published:   June 2011

Provided by:    Frank Rice, Microsoft Corporation

Publishing slides as individual presentations enable a number of scenarios that include viewing the slides in a browser by using the Microsoft PowerPoint Web App. In this topic, you programmatically publish all of the slides in a presentation and then publish a range of slides as separate PPTX files. To complete this task, you must do the following:

In this task, you open a PowerPoint 2010 presentation, open the Visual Basic Editor, and then insert a standard module.

To add a standard module to a PowerPoint presentation

  1. Start PowerPoint.

  2. On the Developer tab, click Visual Basic to open the Visual Basic Editor.

    Note Note

    If you do not see the Developer tab in PowerPoint, click the File tab, and then click Options. In the categories pane, click Popular, select Show Developer tab in the Ribbon, and then click OK.

  3. On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.

In this task, you add programming code to the Visual Basic Editor.

To add code to the Visual Basic Editor

  1. In the Projects pane, click Module1.

  2. Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.

    Sub PublishSlidesDemo()
        ' Demonstrate the Presentation.PublishSlides method.
       
        ' The library URL can either be a file system path, or
        ' a link to a SharePoint Slide Library. For this demonstration,
        ' use a local file path.
       
        ' Modify this path to meet your own needs:
        Const libraryUrl As String = "C:\Temp\"
        ' Publish all the slides:
        PublishSlideRange libraryUrl, True
       
        ' Publish a range of slides:
        ' PublishSlideRange libraryUrl, True, 2, 5
    End Sub
    
    Sub PublishSlideRange(libraryUrl As String, Optional OverWrite As Boolean = True, _
    Optional startSlide As Variant, Optional endSlide As Variant)
       
        If IsMissing(startSlide) And IsMissing(endSlide) Then
            ' Neither endpoint specified. Use ActivePresentation.PublishSlides
            ActivePresentation.PublishSlides libraryUrl, OverWrite
        Else
            If IsMissing(startSlide) Then
                startSlide = 1
            End If
            If IsMissing(endSlide) Then
                endSlide = ActivePresentation.Slides.Count
            End If
           
            ' Make sure the values are in a reasonable range:
            If startSlide < 1 Then
                startSlide = 1
            End If
            If endSlide > ActivePresentation.Slides.Count Then
                endSlide = ActivePresentation.Slides.Count
            End If
           
            Dim rng As SlideRange
           
            ' Create an array containing a list of all the slides to publish:
            ReDim slidesToPublish(1 To (endSlide - startSlide + 1)) As Integer
            Dim counter As Integer
            counter = 1
            Dim i As Integer
            For i = startSlide To endSlide
                slidesToPublish(counter) = i
                counter = counter + 1
            Next i
           
            ' Given the array of slide numbers, publish the slides:
            Set rng = ActivePresentation.Slides.Range(slidesToPublish)
            rng.PublishSlides libraryUrl, OverWrite
        End If
    End Sub
    
    

In this task, you run the code. The PublishSlidesDemo procedure contains code that enables you to save all of the slides in a presentation or just a range of slides as separate PPTX files.

Note Note

The help documentation indicates that the PublishSlideRange method creates a Web presentation in HTML format. However, in truth, the method just creates PPTX files.

To run the code

  • Place your cursor in the PublishSlidesDemo module and then press F5. Navigate to the location specified in the procedure and observe that a PPTX files was created for each slide.

  • Comment the line of code to publish all slides and then uncomment the line that publishes a range of slides. Rerun the PublishSlidesDemo procedure and observe that just the selected PPTX files were created.

Show: