How to check if a cell has a picture?

后端 未结 6 1443
名媛妹妹
名媛妹妹 2020-12-10 18:10

In Excel, I want to check if a specific cell for instance \"C12\" has a picture?
How could I do this?

6条回答
  •  清歌不尽
    2020-12-10 18:24

    I had a situation where I wanted to delete pictures (In my case charts) from selected cells on a worksheet and leave others in place therefore removing all pictures was not an option. I've left behind some debugging and also some extra code to tell the user what is going on.

    Public Sub RemoveUnWantedGraphs()
    
        Dim shp As Shape
        Dim rangeToTest As Range
        Dim c As Range
        Dim shpList
    
        'Set the rangeToTest variable to the selected cells
        Set rangeToTest = Selection
    
        'Loop Over the the selected cells
        For Each c In rangeToTest
    
    
            'Inner loop to iterate over the shapes collection for the activesheet
            Set shpList = ActiveSheet.Shapes
            For Each shp In shpList
    
                Application.StatusBar = "Analysing:- " + c.Address + " Graphs To Find:- " & shpList.Count
    
    
                'If the address of the current cell and the address
                'of the shape are the same then delete the shape
                If c.Address = shp.TopLeftCell.Address Then
    
                    Debug.Print "Deleting :- " & shp.Name
                    shp.Delete
    
                    DoEvents
                End If
    
            Next shp
    
        Next c
    
        Application.StatusBar = ""
    
        MsgBox "All Shapes In Range Deleted"
    
    End Sub
    

提交回复
热议问题