Reputation: 39
Sheet "Symbol Editor" is the only sheet in the workbook.**
Sub AssembleSymbol()
Worksheets("Symbol Editor").Shapes.SelectAll
Selection.Group
End Sub
Before the subroutine AssembleSymbol() is run, there are 3 shapes inserted into the Symbol Editor, then the subroutine is run and I get:
"Excel Runtime Error 438 Object does not support property or method"
Even though I get an error, when you look at the worksheet all shapes are selected and grouped.
The rationale for grouping the Shapes is to save the shapes as 1 collective symbol along with their "relative" positions, to one another, in a "SymbolLibrary" to be used in future, user-defined, "displays"
Any help would be appreciated.
Upvotes: 1
Views: 132
Reputation: 54948
TypeName
With ShapesSub AssembleSymbolOrig()
Worksheets("Symbol Editor").Shapes.SelectAll
MsgBox TypeName(Selection), vbInformation, "TypeName"
If TypeName(Selection) = "DrawingObjects" Then Selection.Group
End Sub
Sub AssembleSymbolStudy()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets("Symbol Editor")
Dim shps As Shapes: Set shps = ws.Shapes
Dim TN As String
Select Case shps.Count
Case 0
TN = TypeName(Selection)
MsgBox "There are no shapes ('" & TN & "').", vbInformation
Case 1
shps.SelectAll
TN = TypeName(Selection)
If TN = "GroupObject" Then
Selection.Ungroup
MsgBox "Ungrouped a group ('" & TN & "').", vbInformation
Else
MsgBox "One shape selected ('" & TN & "').", vbInformation
End If
Case Is > 1
shps.SelectAll
TN = TypeName(Selection)
If TN = "DrawingObjects" Then
Selection.Group
MsgBox "Grouped all shapes ('" & TN & "').", vbInformation
End If
End Select
End Sub
Upvotes: 3