Finance

Charts

Statistics

Macros

Search

Deleting All Images Puzzle in Excel VBA

Removing all puzzle pieces is done using the procedure DeleteAllShapes() , which is called at multiple points in the program:

Code

Sub DeleteAllShapes()
    Dim ShapeObj As Shape
    ThisWorkbook.Worksheets("Sheet1").Activate
    ActiveWindow.DisplayGridlines = False
    For Each ShapeObj In ActiveSheet.Shapes
        ShapeObj.Delete
    Next ShapeObj
    Set ShapeObj = Nothing
End Sub

Explanation:

In Excel, inserting an image from a file is done by going to the Insert tab and clicking on the Pictures button. After selecting the image file, it is inserted into the workbook as an object.

When inserted, the image becomes part of the worksheet’s Shapes collection. This collection includes all objects like pictures, charts, buttons, etc.

The DeleteAllShapes() procedure:

  1. Activates the worksheet named "Sheet1".
  2. Hides the gridlines in the active window by setting ActiveWindow.DisplayGridlines = False.
  3. Uses a For Each loop to iterate through all shapes on the active sheet.
  4. Deletes each shape using the .Delete method.
  5. Cleans up by setting the shape object variable to Nothing.

 

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx