Forum Discussion
keldsor
Oct 27, 2022Brass Contributor
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...
- 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
JKPieterse
Oct 31, 2022Silver Contributor
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
- keldsorOct 31, 2022Brass ContributorTHX ... yesh, it could be stripped a little to minimize the code 😉