Delete Unlocked Pictures from Sheet1 with Code

C

Corey

The below code is being used to remove any values from all cells that are not locked.

But i want to add a line to delete ALL pictures in the same sheet (Sheet1 = Layout Sheet) that are
also NOT LOCKED.

I have some logo's on the sheet that i have LOCKED, so i do NOT want these deleted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Button72_Click()
Application.DisplayAlerts = False
' Delete Unlocked Pictures code here
'
'
' Then clear cell contents that are Unlocked
With Sheet1
..Select
..Unprotect
Dim c As Range
For Each c In Sheets("Layout Sheet").UsedRange
If c.Locked = False Then
c.Value = ""
End If
Next
..Protect
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can anyone help?

Corey....
 
C

Corey

Got it.

Used:

Sub Remove_Images()
Application.ScreenUpdating = False
Sheet1.Select
Dim DrObj
Dim Pict
Set DrObj = ActiveSheet.DrawingObjects
For Each Pict In DrObj
If Pict.Locked = False Then
Pict.Select
Pict.Delete
End If
Next
Application.ScreenUpdating = True
End Sub


The below code is being used to remove any values from all cells that are not locked.

But i want to add a line to delete ALL pictures in the same sheet (Sheet1 = Layout Sheet) that are
also NOT LOCKED.

I have some logo's on the sheet that i have LOCKED, so i do NOT want these deleted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Button72_Click()
Application.DisplayAlerts = False
' Delete Unlocked Pictures code here
'
'
' Then clear cell contents that are Unlocked
With Sheet1
..Select
..Unprotect
Dim c As Range
For Each c In Sheets("Layout Sheet").UsedRange
If c.Locked = False Then
c.Value = ""
End If
Next
..Protect
End With
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can anyone help?

Corey....
 
P

Peter T

If you only want to delete unlocked pictures try -

Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not pic.Locked Then
pic.Delete
End If
Next

Note typically objects, such as inserted pictures, are locked by default.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top