Forum Discussion

keldsor's avatar
keldsor
Brass Contributor
Oct 27, 2022
Solved

Checking for any shapes selected ??

I'm trying to find a way to check if any Shapes are selected because executing then next code is meaningless if no selection is done. There is LOTS of samples out there but way too sophisticated - I...
  • JKPieterse's avatar
    Oct 31, 2022

    keldsor This seems to work:

    Sub TestIfShapeSelected()
        Dim shp As Shape
        Dim obj As Object
        On Error Resume Next
        Set obj = Selection.ShapeRange(1)
        If obj Is Nothing Then
            MsgBox "No shape selected"
        Else
            For Each shp In ActiveSheet.Shapes
                If shp Is obj Then
                    'Shape selected
                    MsgBox "You have selected shape '" & shp.Name & "'"
                End If
            Next
        End If
    End Sub
    

Resources