I have a few presentations with shapes I need to delete, with
- specific .Name
- specific color
Those shapes with specific .Name can be grouped (not in my code). I found code in stackoverflow and tried to modify it.
- Find shape by name and delete it: Specific .Name can be "XXName1" as well "Name1".
If there are no shapes with .Name = "Name1" I get an Error
"Object does not exist"
on the line If .Name = "Name1" Or .Name = "Name2" Then
Sometimes the code works, and then, if there are a lot slides in the presentation, I have an error. When I test with a 1-slide presentation - no error.
- Find shape by color and delete it:
I have an Error
"Object variable or With block variable not set"
I don't understand how to declare variable
Sub DeleteShapes()
Dim oSld As Slide
Dim oShp As Shape
Dim oshpGroup As Shape
Dim Y As Long
Dim L As Long
Dim str As String
For Each oSld In ActivePresentation.Slides
For L = oSld.Shapes.Count To 1 Step -1
With oSld.Shapes(L)
' Find shape by name and delete it
If .Name = "XXName1" Or .Name = "XXName2" Then
.Delete
End If
If .Name = "Name1" Or .Name = "Name2" Then
.Delete
End If
' Find shape by color and delete it
If oShp.Fill.ForeColor.RGB = RGB(0, 0, 0) Or _
oShp.Fill.ForeColor.RGB = RGB(1, 1, 1) Or _
oShp.Fill.ForeColor.RGB = RGB(2, 2, 2) Or _
oShp.Fill.ForeColor.RGB = RGB(3, 3, 3) Then
oShp.Delete
End If
End With
Next L
Next oSld
End Sub
oShp... you want to refer back toWith osld.Shapes(L). - BigBenIf...End If,If...End IftoIf...ElseIf....ElseIf...End If. - BigBen