Thursday, December 5, 2019

 

1.Delete all shapes

Sub Delete_All_Shapes()
    'Delete all Objects except Comments
    On Error Resume Next
    
    ActiveSheet.DrawingObjects.Visible = True
    ActiveSheet.DrawingObjects.Delete
    
    On Error GoTo 0
End Sub

2.Delete specific shape
Option Explicit

Private Const TYPE_FORM_CONTROL As Integer = 8      'Forms controls
Private Const TYPE_ACTIVEX_CONTROL As Integer = 12  'ActiveX control (control toolbox) or a linked or embedded OLE object.
Private Const TYPE_PICTURE As Integer = 13          'Picture


Sub Delete_specific_Shapes()
    Dim myshape As Shape
    For Each myshape In ActiveSheet.Shapes
 
        Debug.Print "-----"
        Debug.Print "myshape.Type/Name", myshape.Type, myshape.Name
        Debug.Print "", myshape.TopLeftCell.Address, myshape.BottomRightCell.Address
        
 
        If myshape.Type = TYPE_FORM_CONTROL Then
            myshape.Delete
            
        
        
        ElseIf myshape.Type = TYPE_ACTIVEX_CONTROL Then
'            myshape.Delete

        
        ElseIf myshape.Type = TYPE_PICTURE Then
'            myshape.Delete

        
        End If
        

        ' You can also use  myshape.Visible = False
 
    Next myshape
End Sub



Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Lập trình hệ thống nhúng Linux . Powered by Luong Duy Ninh -