My delete picture code doesn't work

ashley12

New Member
Joined
Dec 6, 2020
Messages
43
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I used some codes to insert a picture in a sheet. Then later I want to delete it, but leave the command button. I tried 3 different codes but none of them works.

This one doesn't do anything
VBA Code:
Dim Pic As Shape
        For Each Pic In ActiveSheet.Shapes
            If Pic.Type = msoPicture Then
            Pic.Delete
            End If
        Next

This one says "Type mismatch"
VBA Code:
Dim Pic As Picture
        For Each Pic In ActiveSheet.Pictures
            Pic.Delete
        Next


This one delete both the picture and my command button
VBA Code:
Activesheet.Pictures.Delete


And here is my code to add the picture in if that helps.
VBA Code:
Sub Present_Pic()
    If PicPath = "" Then Exit Sub
  
    Dim Pic As Picture, ImageCell As Range

    Set ImageCell = Interface.Cells(20, 8)

    Set Pic = Interface.Pictures.Insert(PicPath)
    With Pic
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = 400

    End With
  
    Set Pic = Nothing

End Sub

Thank you all in advance
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
it might pay to see if your pics are
VBA Code:
Pic.type=msolinkedpicture 'or
Pic.type=msoEmbeddedOLEObject
 
Upvote 0
Solution
Thank you. I've check and it says the type of Pic is "Shape" ?
Is there a more specific property it than type?
 
Upvote 0
check Shape.Name
or if there are no other shapes, you can delete them all, but considering when you trued that it errored there must be some others.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top