Results 1 to 3 of 3

Thread: Strange behavior for Excel 365 when deleting pictures

  1. #1
    Board Regular
    Join Date
    Aug 2016
    Posts
    153
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Strange behavior for Excel 365 when deleting pictures

    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 by mcomp72; Sep 7th, 2019 at 05:46 PM.

  2. #2
    Board Regular
    Join Date
    Nov 2009
    Posts
    219
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Strange behavior for Excel 365 when deleting pictures

    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 by ISY; Sep 7th, 2019 at 06:25 PM.

  3. #3
    Board Regular
    Join Date
    Aug 2016
    Posts
    153
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Strange behavior for Excel 365 when deleting pictures

    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!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •