Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用VBA清除PowerPoint中所有信息的幻灯片母版?_Vba_Loops_Slide_Powerpoint - Fatal编程技术网

如何使用VBA清除PowerPoint中所有信息的幻灯片母版?

如何使用VBA清除PowerPoint中所有信息的幻灯片母版?,vba,loops,slide,powerpoint,Vba,Loops,Slide,Powerpoint,我想打开当前文件夹中的每个PowerPoint(*.pptx),清除幻灯片母版中的所有图像和文本框,然后保存 (上面说我的帖子大部分都是代码,所以我需要补充更多细节,这里引用乔治·华盛顿的一句话,“如果你尊重自己的声誉,就要与品质优良的人交往;因为独处总比与坏人为伍好”) 新代码 Sub DeleteSlideMasterShapes() Dim i As Long Dim shp As Shape With ActivePresentation For

我想打开当前文件夹中的每个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的形状,请使用以下命令

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 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的形状,请使用以下命令

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

另一种方法是,如果要从所有幻灯片母版和母版布局中删除所有形状:

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

您需要至少有一个幻灯片母版。您不能删除所有slidemaster。如果您试图删除最后一个,它将抛出一个错误。这就像试图删除工作簿中的所有工作表。关于清除SM,你能解释一下你到底想实现什么吗?我有幻灯片母版,标题中包含图像和文本框,我想清除其中当前的信息。你至少需要一个幻灯片母版。您不能删除所有slidemaster。如果您试图删除最后一个,它将抛出一个错误。这就像试图删除工作簿中的所有工作表。关于清除SM,你能解释一下你到底想实现什么吗?我有幻灯片母版,标题中包含图像和文本框,我想清除它们当前在标题中的信息。嘿,史蒂夫,谢谢你的方法。我想测试它,但我对VBA非常陌生,2天了,不知道如何连接到子循环文件()您已经完成了。。。只要用我的DeleteSlideMasterShapes子对象替换你的DeleteSlideMasterShapes子对象就行了。我得到了下面的错误,编译错误:在“Dim fso As New FileSystemObject”行的sub loopFiles()中没有定义用户定义的类型?如果是这样,请使用工具|引用添加对“Microsoft脚本运行时”的引用嘿,Steve,谢谢你的方法。我想测试它,但我对VBA非常陌生,2天了,不知道如何连接到子循环文件()您已经完成了。。。只要用我的DeleteSlideMasterShapes子对象替换你的DeleteSlideMasterShapes子对象就行了。我得到了下面的错误,编译错误:在“Dim fso As New FileSystemObject”行的sub loopFiles()中没有定义用户定义的类型?如果是,请使用工具|引用添加对“Microsoft脚本运行时”的引用