Adding all shapefiles in a folder and grouping them in a layer

Discussion created by gatilloz on Aug 3, 2011
Latest reply on Aug 8, 2011 by gatilloz
Hi everyone, I 'd like to see if you can help me with this. I already have the above code for adding all the shapefiles in a specific folder, but I need to have them grouped in a new layer group. What should I add? Thanks a lot.

Public Sub agregarshp()

Dim MxDoc As IMxDocument
Set MxDoc = ThisDocument
Dim pMap As IMap
Set pMap = MxDoc.FocusMap

Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFeatureLayer As IFeatureLayer
Dim pMxDocument As IMxDocument

Dim strDir As String
Dim strFileName As String
Dim cntFilesProc As Integer

strDir = ("C:\Unif_trabajo")

strFileName = Dir(strDir & "\*.shp")

cntFilesProc = 0

Do While Len(strFileName) > 0
    cntFilesProc = cntFilesProc + 1
    Debug.Print strFileName

    Set pWorkspaceFactory = New ShapefileWorkspaceFactory
    Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strDir, 0)

    Set pFeatureLayer = New FeatureLayer
    Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(strFileName)
    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName
    Set pMxDocument = Application.Document
    Set pMap = pMxDocument.FocusMap
    pMap.AddLayer pFeatureLayer
    strFileName = Dir

End Sub