删除Powerpoint演示文稿中的命名对象

时间:2015-01-20 12:59:42

标签: vba object powerpoint

我有一些名为" MYobject"在PowerPoint演示文稿中。我需要一个宏来删除名为" Myobject"的那些对象。我怎么能这样做?

我用来标记对象的代码:

Sub TagObject()

On Error GoTo ErrorHandler

    Dim oSh As Shape

    For Each oSh In ActiveWindow.Selection.ShapeRange
        oSh.Tags.Add "Myobject", "YES"
    Next
    MsgBox "Done! Object has now been tagged.", vbInformation
    Exit Sub

ErrorHandler:

    MsgBox "Please select an object before tagging.", vbExclamation
    End Sub

1 个答案:

答案 0 :(得分:1)

这将使用Myobject标签删除所有形状=“是”

Sub DeleteMyObjects()

    Dim oSl As Slide
    Dim oSh As Shape
    Dim x As Long

    ' note that this will not delete shapes
    ' within groups
    For Each oSl In ActivePresentation.Slides
        For x = oSl.Shapes.Count To 1 Step -1
            If UCase(oSl.Shapes(x).Tags("Myobject")) = "YES" Then
                oSl.Shapes(x).Delete
            End If
        Next    ' Shape
    Next    ' Slide

End Sub