1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Sub test()
lFolder = "K:\VBA EXCEL\" 'lFolder a adapter
Extension = ".xls" 'extension à adapter
tabl = ListFileByExtension(lFolder, Extension) 'récupération de la liste avec la fonction
Cells(1, 1).Resize(UBound(tabl), UBound(tabl, 2)) = tabl
'exemple pour ta combobox
'tacombobox.List = ListFileByExtension(lFolder, Extension)
End Sub
Function ListFileByExtension(lFolder, Optional ext = ".*")
'created patmeziere Allias patricktoulon for @MODUS57 12/12/2024
Dim I&
Dim Criteres As Long
Dim ItemVu As String
Dim tbl()
ReDim tbl(1 To 3, 1 To 1)
'****************************************************
'ici on determine les critères de grabb
'comme on va lister on démarre par vbdirectory ensuite les normal pas les system pas les cachés
'il est bien évident que les sous dossiers vont être exemptés dans cette version et cela sera géré dans les instructions conditionnelles
'c'est ce que l'on appelle une addition logique et non mathématique
critères = vbDirectory And vbNormal And Not vbSystem And Not vbHidden
'*******************************************************
ItemVu = Dir(lFolder, Criteres) 'dir avec critères
Do While ItemVu <> ""
If Left(ItemVu, 1) <> "." Then
If (GetAttr(lFolder & ItemVu) And vbDirectory) <> vbDirectory Then
If ext = ".*" Then ext = Right(ItemVu, 4)
If Right(ItemVu, Len(ext)) = ext Then
I = I + 1: ReDim Preserve tbl(1 To 3, 1 To I)
tbl(1, I) = ItemVu
tbl(2, I) = FileDateTime(lFolder & ItemVu)
tbl(3, I) = FileLen(lFolder & ItemVu) / 1000 & "Ko"
End If
End If
End If
ItemVu = Dir
Loop
ListFileByExtension = Application.Transpose(tbl)
End Function |
Partager