Strange behavior for Excel 365 when deleting pictures

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
275
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
Platform
  1. Windows
  2. MacOS
I have run across some strange behavior, and am wondering if anyone else has experienced this.

I have a worksheet where the user can import pictures via VBA code. I also have a couple of checkboxes (form controls) on that sheet.

I have a button that allows the user to clear the sheet of all data, including the pictures. What is strange is that I have found that when running the code to clear the sheet, sometimes the code will delete one or both of the checkboxes. Sometimes it deletes one of them, sometimes it deletes both of them, and sometimes it doesn't delete either of them. But the code is the SAME each time I test it, so why it is so inconsistent makes no sense to me.

I have stepped through the code and found the line where it is sometimes deleting the checkboxes.

Code:
ThisWorkbook.Sheets("Sheet1").Pictures.Delete

I wouldn't think that checkboxes would be considered pictures, which is why am using this code rather than .Shapes.Delete.

Does anyone have any suggestions of what I might try to stop this problem from happening? Or even better, does anyone know why this could be happening at all?

BTW, I am running Windows 10 (64-bit) with Excel 365 (32-bit).
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,

Code:
Sub Test()
    Dim sh As Shape
    For Each sh In Sheets("Sheet1").Shapes
        MsgBox sh.Type & Chr(13) & sh.Name
        Rem sh.Delete
    Next sh
End Sub
 
Last edited:
Upvote 0
Hi ISY. I think I see what you're getting at. Once I know the sh.Type of Pictures, I tell it to only delete the Shape if it matches that particular sh.Type. Thanks for the tip!
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

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