VBA PowerPoint To Delete Slide Notes
In this post, let’s look at how we can use VBA in PowerPoint to delete all the slide notes in your presentation file. This can be very useful if you want to delete all the notes in a presentation before you send it out to your audience.
You don’t need this if you only have like three or four slides, but it definitely starts to make sense when you have more than twenty slides. Also makes sense if you need to do this sort of thing often. Here is the code:
Sub DeleteAllSlideNotes()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.NotesPage.Shapes.Placeholders
If shp.Type = msoPlaceholder And shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = ""
End If
Next shp
Next sld
End Sub
In the above code, we declare two variables – a ‘Slide’ variable and a ‘Shape’ variable. We then loop through all of the slides using a ‘For Each’ loop and if the slide has notes, we set the text in the shape variable to a blank string.
By checking that the shape type is a ‘msoPlaceholder’ and that the Text Frame has text, we can avoid using error handling which makes the code cleaner.
The video below provides an explanation and also shows you where to place the code. Remember that you need to have your ‘Developer’ tab enabled in the ribbon. This can be done by going to File -> Options -> Customize Ribbon. Then make sure the Developer tab is selected on the right.
In this example, we’re deleting the slide notes from the Active Presentation. This means that the presentation needs to be saved as a macro-enabled presentation (.pptm) instead of the typical presentation (.pptx).
If you don’t want to change the extension of your file, you can modify the code so that it opens up an existing .pptx file and have it loop through that instead. You will need to add code to declare and assign the presentation file variable, open it, the looping and setting of the comments to an empty string will be the same, save the opened presentation file, and finally, close it.
Hope you’ve found this video and code useful. We’ll have more code that helps you automate your work in future posts.