安全地创建选择集很重要。给你一个子程序吧:
Public Function CreateSelectionSet(AcadDoc As AcadDocument, ByVal Name As String) As AcadSelectionSet
On Error GoTo ERR_HANDLER
Dim SSetObj As AcadSelectionSet
Dim SSetColl As AcadSelectionSets
Set SSetColl = AcadDoc.SelectionSets
Dim Index As Integer
Dim Found As Boolean
Found = False
For Index = 0 To SSetColl.Count - 1
Set SSetObj = SSetColl.Item(Index)
If StrComp(SSetObj.Name, Name, 1) = 0 Then
Found = True
Exit For
End If
Next
If Not (Found) Then
Set SSetObj = SSetColl.Add(Name)
Else
SSetObj.Clear
End If
Set CreateSelectionSet = SSetObj
Exit Function
ERR_HANDLER:
Debug.Print "Error in Function CreateSelectionSet: " & Err.Number & " -- "; Err.Description
Resume ERR_END