Creation d'une listbox en fonction d'une boucle

christ-94

XLDnaute Occasionnel
Bonjour

J'ai recupere ce code que j'aimerais adapte
Il recherche la date de creation, de modification des fichiers
Il faut place en a1 le nom du fichiers sous la forme
C:\tmp\test.xls "on peut recherche plusieurs fichiers"
puis la macro va cherche les infos
Le probleme , j'aimerais que les infos ainsi trouvées soit place dans une listbox "Je n'arrive pas a la crée (le resultat varie en fonction du nombre de fichiers a recherche)".



Code:
Sub test()
Dim fin As Long 'déclare la variable fin
Dim b As Long 'déclare la variable b
'Dim b, fs, f, s 'déclare la variable fs,f,s

fin = Range("a65536").End(xlUp).Row 'définit la variable de fin

For b = 1 To fin 'boucle
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(Range("a" & b))


'affiche le resultat
Range("a" & (b + 4)) = Range("a" & b)
Range("a" & (b + 5)) = "Créé le : " & f.DateCreated
Range("a" & (b + 6)) = "Dernier accès le : " & f.DateLastAccessed
Range("a" & (b + 7)) = "Dernière modification le : " & f.DateLastModified
Next b

End Sub


Merci de votre aide
 

john

XLDnaute Impliqué
Re : Creation d'une listbox en fonction d'une boucle

Salut,

As-tu essayé ceci :

Sub test()
Dim fin As Long 'déclare la variable fin
Dim b As Long 'déclare la variable b
'Dim b, fs, f, s 'déclare la variable fs,f,s

fin = Range("a65536").End(xlUp).Row 'définit la variable de fin
Feuil1.ListBox1.Clear
For b = 1 To fin 'boucle
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(Range("a" & b))
'affiche le resultat
Feuil1.ListBox1.AddItem Range("a" & b)
Feuil1.ListBox1.AddItem "Créé le : " & f.DateCreated
Feuil1.ListBox1.AddItem "Dernier accès le : " & f.DateLastAccessed
Feuil1.ListBox1.AddItem "Dernière modification le : " & f.DateLastModified
Next b
End Sub

Mais tu dois placer une listbox sur ta feuille excel !!!! sinon tu aura un message d'erreur.

Bonne fin de journée.

John
 

christ-94

XLDnaute Occasionnel
Re : Creation d'une listbox en fonction d'une boucle

Merci pour la reponse

voici le code

Code:
Sub Info_fichiers()
Dim fs, f, s

Set fs = CreateObject("Scripting.FileSystemObject")

s = UCase(" Date creation") & vbTab & vbTab
s = s & "Date dernier acces" & vbTab & vbTab
s = s & "Date dernier modification" & vbTab
s = s & "Nom fichiers" & vbCrLf

s = s & " ---------------------" & vbTab & vbTab
s = s & " -----------------------" & vbTab & vbTab
s = s & " -----------------------------" & vbTab
s = s & " ------------------" & vbCrLf & vbCrLf

fin = Range("B65536").End(xlUp).Row 'définit la variable fin
For b = 1 To fin 'boucle
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(Range("B" & b))

s = s & f.DateCreated & vbTab
s = s & f.DateLastAccessed & vbTab
s = s & f.DateLastModified & vbTab
s = s & Range("B" & b) & vbTab & vbCrLf
Next b

MsgBox s, 0, "Infos d'accès au fichier"
End Sub
 

Discussions similaires