PDA

View Full Version : Finding Shape types WITHOUT selecting the shape ?



ksor
10-26-2022, 11:26 AM
I have a sheet with some rectangles, arrows and triangles.

Each rectangle has a number as it's Name and when I want to add new rectangles I need to find the biggest 'number' Name and count further from there.

This code run through the shapes and can find out the types - but can it be done WITHOUT selecting the shape:



Sub IdentifyShapes()
Dim s As Shape
For Each s In ActiveSheet.Shapes
s.Select
Debug.Print s.Type, TypeName(Selection)
Next s
End Sub

snb
10-26-2022, 12:01 PM
Sub M_snb()
For Each it In ActiveSheet.Shapes
msgbox it.Type & vbtab & TypeName(it)
Next
End Sub

Paul_Hossler
10-27-2022, 06:09 PM
Let Excel do the work



Option Explicit


Sub NextRect()
Dim oRect As Shape
Dim N As Long
Dim v As Variant

For Each oRect In ActiveSheet.Shapes
With oRect
If .Type = msoAutoShape Then
If .AutoShapeType = msoShapeRectangle Then
v = Split(.Name, " ")
If CLng(v(1)) > N Then N = CLng(v(1))
End If
End If
End With
Next

MsgBox "Next number is " & (N + 1)
End Sub