About Sorting Layers and Linetypes (VBA/ActiveX)

You can iterate through the Layers and Linetypes collections to find all the layers and linetypes in a drawing.

Iterate through the Layers collection

The following code iterates through the Layers collection to gather the names of all the layers in the drawing. The names are then displayed in a message box.

Sub Ch4_IteratingLayers()
  Dim layerNames As String
  Dim entry As AcadLayer
  layerNames = ""
  For Each entry In ThisDrawing.Layers
    layerNames = layerNames + entry.Name + vbCrLf
  Next
  MsgBox "The layers in this drawing are: " + vbCrLf + layerNames
End Sub