簡體   English   中英

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

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

我想在當前文件夾中打開每個PowerPoint(* .pptx)並清除所有圖像和文本框的幻燈片母版,然后保存。

(它說我的帖子主要是代碼,所以我需要添加更多細節,所以這里引用喬治華盛頓,“如果你尊重自己的聲譽,請與優質男士聯系;因為獨處而不是糟糕的公司更好“)

新代碼

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

要刪除slidemaster的Shapes,請使用此選項

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM