The error lies in your function SelectAll: there are a few things wrong:
1. Firstly, you did not declare what the Type the function returns, which is allowed while not being good practice, thus, the function would return Variant type. However, with this function you DID not actually return anything; that is, you need to hate a line of code before "End Function", something like
Private Function SelectAll()
... ...
SelectAll = ....
End Function
So, your function returns an empty value of Variant type. Therefore, your main code, after the Function is called, even assume you do not have other error in SelectAll(), obviously will not work, because
entities = SelectAll()
get you nothing in the "entities" object array.
2. About the error you get at
Set ssetObj = ThsiDrawing.SelectionSet.Add("SSET")
I bet when you run the code first time, this line works OK (but not the next line, as aforementioned), because the drawing already has a SelectionSet, names as "SSET" due to the previous run, thus the error. When creating a AcadSelectionSet, ALWAYS test if there is one with the same name allready exists; if yes, either re-use the existing one, or create with different name.
a. you can:
Dim ssetObj As AcadSelectionSet
Dim ss As AcadSelectionSet
For Each ss in ThisDrawing.SelectionSets
if Ucase(ss.Name)="SSET" Then
Set ssetObj=ss
ssetObj.Clear
Exit For
End If
Next
If ssetObj Is Noting Then
Set ssetObj = ThisDrawing.SelectioNSets.Add("SSET")
End If
... ...
b. you can also use error catching to make your code a bit simple, like this:
On Error Resume Next
Dim ssetObj As AcadSelectionSet
'' Set it to existing one
Set ssetObj = ThisDrawing.SelectionSet("SSET")
'' If no existing found, error is raised
If err.Number <> 0 Then
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
End If
On Error GoTo 0
... ...
3. Even you actually return the selectionset (ssetObj) with a line of code in end SelectionAll(), like
Private Function SelectAll()
...
ssetObj,Select acSelectionSetAll......
Set SelectAll= ssetObj
End Function
The code STILL DOES NOT work, because CopyFrom expect an AcadObject array, not an AcadSelectionSet. You MUST convert the AcadSelectionSet to object array.
4. If your code is meant to run with AutoCAD VBA, you DO NOT declear a variable "ThisDrawing", which is AutoCAD VBA' reserved object
Anyway, Following should be how the SelectAll() function look like (not tested, just off my head):
Private Function SelectAll() As Variant
Dim mode As Integer
Dim ssetObj As AcadSelectionSet
Dim ss As AcadSelectionSet
For Each ss In ThisDrawing.SelectionSets
If UCase(ss.Name)="SSET" Then
Set ssetObj = ss
ssetObj.Clear
Exit For
End If
Next
If ssetObj Is Nothing Then
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
End If
Dim FilterType As Integer
Dim FilterData As Variant
FilterType = 67
FilterData = 0
ssetObj.Select acSelectionSetAll, , , FilterType, FilterData
Dim ents() As AcadEntity
Dim i As Inetger
For Each ent in ssetObj
ReDim Preserve ents(i)
Set ents(i)=ent
i = i + 1
Next
SelectAll = ents
End Function
HTH