Delete Graphic

  • Thread starter Thread starter sspittell
  • Start date Start date
S

sspittell

I have used the following code to insert a jpeg file. But cannot figur
out how to delete the graphic, to clear the sheet.

Dim pic As Picture
Dim varInput As String

varInput = InputBox("Please Type in the path and Name to you
Electronic Signature, C:\mysig.jpg")
Sheets("chgMemo").Select
Range("I49").Select

'Unprotect Sheet
ActiveSheet.Select
ActiveCell.Activate
ActiveSheet.Unprotect password:="1234"
Set pic = ActiveSheet.Pictures.insert(varInput)
pic.Top = Range("I49:W49").Top
pic.Left = Range("I49:W49").Left
pic.Width = Range("I49:W49").Width
pic.Height = Range("I49:W49").Height
'Protect sheet
ActiveSheet.Select
ActiveCell.Activate
Range("AA49").Select
Range("AA49").Value = Now()
ActiveSheet.Protect password:="1234"


Here is what I think is close to correct

Private Sub cmdClear_Click()
' Define a For-Each loop of all the drawing objects on the
' active worksheet.
For Each DrawObj In ActiveSheet.DrawingObjects
' Define Cell_Ref as the top left cell address of eac
Drawing
' Object.
Range("I49:W49") = DrawObj.TopLeftCell.Address
' Define a For-Each loop of all the cells with the range
' Print_Area.
For Each Cell In Range("I49:W49")
' If the Object's top left cell address is the same a
a
' cell in the print range.
If Range("I49:W49") = Cell.Address Then
' Then delete the object.
DrawObj.Delete
' End the IF statement.
End If
' Loop through next cell.
Next Cell
' Loop through next DrawObj.
Next DrawObj
End Su
 
HI.

Try this:
Private Sub cmdClear_Click()
Dim r As Range
' Define a For-Each loop of all the drawing objects on the
' active worksheet.
For Each Drawobj In ActiveSheet.DrawingObjects
' Define Cell_Ref as the top left cell address of
eachDrawing
' Object.
' don't need next line
'r = Drawobj.TopLeftCell.Address
' Define a For-Each loop of all the cells with the range
' Print_Area.
For Each cell In Range("I4:W4")
' If the Object's top left cell address is the same asa
' cell in the print range.
If (cell.Address = Drawobj.TopLeftCell.Address) Then
' Then delete the object and leave this loop
Drawobj.Delete
Exit For
' End the IF statement.
End If
' Loop through next cell.
Next cell
' Loop through next DrawObj.
Next Drawobj
End Sub

good luck.
 
Another option is to give the picture a nice name when you add it (especially
useful if you're doing it in code).

Then you could just loop through the pictures and delete them if the name
matched your criteria.
 

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

Back
Top