Search code examples
vbaloopsslidepowerpoint

How to clear Slide Master of all information in PowerPoint using VBA?


I would like to open every PowerPoint (*.pptx) in current folder and clear the Slide Master of all images and text boxes and then save.

(It says my post is mostly code so I need to add more detail, so here is a quote by George Washington, "Associate with men of good quality if you esteem your own reputation; for it is better to be alone than in bad company")

New code

Sub DeleteSlideMasterShapes()
    Dim i As Long
    Dim shp As Shape

    With ActivePresentation
        For i = .Designs.Count To 1 Step -1
            For Each shp In .Designs(i).SlideMaster.Shapes
                shp.Delete
            Next
        Next i
    End With
End Sub

Sub loopFiles()

Dim fso As New FileSystemObject
Dim fil As File
Dim fold As Folder
Dim yourfolder As String

Set fold = fso.GetFolder(Application.ActivePresentation.Path)

For Each fil In fold.Files

    If InStr(1, fil.Name, ".pptx") > 0 Then
        Application.Presentations.Open fil.Path

        Call DeleteSlideMasterShapes

        ActivePresentation.Save
        ActivePresentation.Close

    End If

Next fil

End Sub

Solution

  • Further to my comments, if you want to delete the slide master then use this

    Sub DeleteSlideMaster()
        Dim i As Long
    
        With ActivePresentation
            On Error Resume Next
            For i = .Designs.Count To 1 Step -1
                .Designs(i).SlideMaster.Delete
            Next i
            On Error GoTo 0
        End With
    End Sub
    

    To delete Shapes of a slidemaster, use this

    Sub DeleteSlideMasterShapes()
        Dim i As Long
        Dim shp As Shape
    
        With ActivePresentation
            For i = .Designs.Count To 1 Step -1
                For Each shp In .Designs(i).SlideMaster.Shapes
                    shp.Delete
                Next
            Next i
        End With
    End Sub
    

    If I have not understood your query then please feel free to ask