建立一个函数:
Private Function CreateSSet(ByVal name As String) As AcadSelectionSet On Error GoTo ERR_HANDLER
Dim ssetObj As AcadSelectionSet Dim SSetColl As AcadSelectionSets Set SSetColl = ThisDrawing.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 'Important. End If Next
If Not (found) Then Set ssetObj = SSetColl.Add(name) Else ssetObj.Delete ' Set ssetObj = SSetColl.Add(name) End If
Set CreateSSet = ssetObj
Exit Function ERR_HANDLER: '----------------------------------------------- ' just print the error the the debug window. Debug.Print "Error in sub CreateSSet: " & Err.Number & " -- "; Err.Description Resume ERR_END