detecting when a user deletes an image (VBA)

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I have a little dilemma.

I have a worksheet which has a button to import a picture into a cell. It names the picture 'Image1'...

When it imports, the button disappears and is replaced with a 'delete picture' button, which deletes and resets the buttons to import again...

However, if the user just deletes the picture (by highlighting and pressing delete), it leaves the 'remove' button and breaks the process...

Is there a way of detecting whether the user has deleted the image manually and then I can run the code accordingly?

I have tried Worksheet_SelectionChange and Worksheet_Change but neither of these seem to detect a picture being deleted from the sheet...

If you can point me in the right direction, I'd be very happy. Thanks and Merry Christmas :)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try something like this:-
NB:- Change Picture file path to suit !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG17Dec08
[COLOR="Navy"]Dim[/COLOR] Pic [COLOR="Navy"]As[/COLOR] Picture, fd [COLOR="Navy"]As[/COLOR] Boolean
[COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] [COLOR="Navy"]Resume[/COLOR] [COLOR="Navy"]Next[/COLOR]
    fd = IIf(ActiveSheet.Shapes("Image1").Name <> "", True, False)
[COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] GoTo 0
[COLOR="Navy"]If[/COLOR] Not fd [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]With[/COLOR] Range("A1")
    [COLOR="Navy"]Set[/COLOR] Pic = .Parent.Pictures.Insert("C:\Users\USER1\Desktop\Bird Pictures\5.jpg")
       Pic.Top = .Top
        Pic.Left = .Left
        Pic.Height = .Height * 3
        Pic.Width = .Width * 3
        Pic.Name = "Image1"
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Else[/COLOR]
   ActiveSheet.Shapes("Image1").Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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