如何使用VBA清除PowerPoint中所有信息的Slide Master?

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

我想打开当前文件夹中的每个 PowerPoint (*.pptx) 并清除所有图像和文本框的幻灯片母版,然后保存。

(它说我的 post 主要是代码,所以我需要添加更多细节,所以这是乔治华盛顿的引述,"Associate with men of good quality if you esteem your own reputation; for it is better to be alone than in bad company")

新代码

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

根据我的评论,如果您想删除幻灯片母版,请使用此

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

要删除幻灯片母版的形状,请使用此

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 DeleteSlideMasterShapes()
'   Including shapes on layouts

    Dim oDes As Design
    Dim oLay As CustomLayout

    With ActivePresentation

        ' For each slide master:
        For Each oDes In .Designs

            ' Delete the shapes on the master
            oDes.SlideMaster.Shapes.Range.Delete

            ' Then delete the shapes from each layout under
            ' the slide master:
            For Each oLay In oDes.SlideMaster.CustomLayouts
                oLay.Shapes.Range.Delete
            Next

        Next

    End With

End Sub