Delete all objects - autocad vba

Public Sub deleteall()

Set newss = vbdPowerSet("tests")

    newss.Select acSelectionSetAll 'select all entities (no filters)
    
    For Each objEntity In newss

        objEntity.Erase

    Next
    newss.Delete 'delete the selection set object (not the entities)


End Sub

 

 

Public Function vbdPowerSet(strName As String) As AcadSelectionSet

  Dim objSelSet As AcadSelectionSet

  Dim objSelCol As AcadSelectionSets

  Set objSelCol = ThisDrawing.SelectionSets

    For Each objSelSet In objSelCol

      If objSelSet.Name = strName Then

        objSelCol.Item(strName).Delete

        Exit For

      End If

    Next

  Set objSelSet = objSelCol.Add(strName)

  Set vbdPowerSet = objSelSet

End Function