PDA

View Full Version : ActiveSheet.DrawingObjects.delete except...



daniels012
12-18-2007, 01:48 PM
I want to
ActiveSheet.DrawingObjects.Delete
Except "Button 219" and "Button 221"
What would be my VBA approach?

Michael

lucas
12-18-2007, 02:55 PM
Try this Michael:
Sub delSomeshapesFromAllSheets()
Dim Shp As Shape
Dim wk As Worksheet
For Each wk In ActiveWorkbook.Worksheets
For Each Shp In wk.Shapes
If Shp.Name <> "Button 219" And Shp.Name <> "Button 221" Then
Shp.Delete
End If
Next
Next
End Sub

lucas
12-18-2007, 03:01 PM
Sorry Michael, I misread the question. The previous code was for all worksheets in the workbook. The following is for the active worksheet only...
Option Explicit
Sub delSomeshapesFromAllSheets()
Dim Shp As Shape
For Each Shp In ActiveSheet.Shapes
If Shp.Name <> "Button 219" And Shp.Name <> "Button 221" Then
Shp.Delete
End If
Next
End Sub

daniels012
12-18-2007, 06:56 PM
Thank You very much!
That worked charmingly!
Michael

lucas
12-20-2007, 10:05 AM
Be sure to mark your thread solved using the thread tools at the top of the page.