VBA code to delete all pictures but one that matches the workbook name

  • Hi
    I have below code that deletes all pictures but the one that is called "PNG".




    What I want it to replace the work "png" with the current active workbook name.


    Can one of you wonderful people modify the code?


    thanks for your help

  • Re: VBA code to delete all pictures but one that matches the workbook name


    If the pictures name also include the file extension, you may simply try like....


    If pic.Name <> ActiveWorkbook.Name Then


    And if the picture name doesn't include the file extension, you may try like.....

  • Re: VBA code to delete all pictures but one that matches the workbook name


    Thanks
    This is working great. I used the name without extension code.


    I forgot to mention this in my original post but I have a picture in the workbook that I do not want to delete. It is called "crown".


    can you modify the code so it does not delete the "crown" picture and the one that is same name as the workbook?


    thanks for your help

  • Re: VBA code to delete all pictures but one that matches the workbook name


    Try this.....