Oct 27 2022 02:28 AM
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 wonder WHY it is so complicated to do such simple thing !
I found this code inserted in the start of any of my Subs that need to have some shapes selected:
If TypeName(Selection) = "Range" Then Exit Sub
It works eventhough NOTHING seems to be selected - maybe there IS something selected, but I have turned "Marking Objects" ON and therefore can't see the active cell marking.
But have I just misunderstood - is there a better practice when SHAPES must be selected ?
Oct 31 2022 04:18 AM
Solution@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
Oct 31 2022 05:28 AM
Oct 31 2022 04:18 AM
Solution@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