PDA

View Full Version : Clear .jpeg in a specific range



chem101
10-19-2010, 08:43 AM
Hello Everyone,

I'm trying to clear a .jpeg from a specific range on a worksheet. A VBAX member was kind enough to provide me with the code shown below. It does a great job but it does delete all of the pics on the spreadsheet. Can it be modified so that only the .jpeg in the specified range gets cleared? I tried to modify it without success.

I appreciate your help!!

Sub Proc2()
' Remove pictures
Dim DrObj
Dim Pict
Set DrObj = wksWHMaster.DrawingObjects
For Each Pict In DrObj
If Left(Pict.Name, 7) = "Picture" Then
Pict.Select
Pict.Delete
End If
Next
End Sub

p45cal
10-20-2010, 10:42 AM
Assuming that wksWHMaster is a sheet,

Sub blah()
For Each Pict In wksWHMaster.Pictures
If TypeName(Pict) = "Picture" Then Pict.Select
Next
End Sub
may work for you and is a bit tidier.
Now as to deleting a picture to be found on a range in a worksheet, each picture has a topleftcell and a bottomrightcell viz.:

Sub blaha()
For Each Pict In wksWHMaster.Pictures
If TypeName(Pict) = "Picture" Then
' MsgBox Pict.TopLeftCell.Address
' MsgBox Pict.BottomRightCell.Address
If Not Intersect(Pict.TopLeftCell, Range("I19:J20")) Is Nothing Then
Pict.Select
'Pict.delete
End If
End If
Next
End Sub