Thursday, June 30, 2016

VBA code to delete multiple picture from worksheet !!!

Use picture and images is very good practice to make excel projects more interactive, Sometimes, there is a need to delete pictures from the workbook. It will be quite tedious task to select each picture and delete it manually.

Such task can be automate using small excel VBA code. Which will delete all pictures from active worksheet.





Here is the code which will delete all pictures from active worksheet:

Sub Delete_Picture()
' Author: Dreams24
' Written for VBA Tricks and tips blog
http://vbatricksntips.blogspot.com
  
   'Declare Variables
    Dim Pic As Object
    
    Application.ScreenUpdating = False
    
    On Error GoTo Err
    
    For Each Pic In ActiveSheet.Pictures
        Pic.Delete
    Next Pic
    
Err:
    
    If Err.Number <> 0 Then
        MsgBox Err.Description
    End If
    
    Application.ScreenUpdating = True

End Sub

No comments: