Function fctChargerLst(sNomDossier As String, sNomFichierAvcExt As String, sNomBase As String, sNomEnteteCol As String) As ADODB.Recordset
' Gestion des erreurs
On Error GoTo fctChargerLst_Error
' Récupérer le répertoire courant
Dim sRepertoire As String
sRepertoire = Mid(ThisWorkbook.Path, 1, InStrRev(ThisWorkbook.Path, "\") - 1)
' Chemin complet Répertoire + Fichier + Extension
Dim sCheminComplet As String
sCheminComplet = sRepertoire & "\" & sNomDossier & "\" & sNomFichierAvcExt
' Connexion au fichier
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & sCheminComplet & ";"
' Requête sur la table
Set rs = cnn.Execute("SELECT [" & sNomEnteteCol & "] FROM " & sNomBase & " where [" & sNomEnteteCol & "]<>''")
' Affecter les enregistrements à la fonction
Set fctChargerLst = rs
On Error GoTo 0
Exit Function
fctChargerLst_Error:
MsgBox "Erreur " & Err.Number & " (" & Err.Description & ") dans la procédure fctChargerLst du document VBA Feuil2"
End Function