jeanjeandada
Messages postés152Date d'inscriptionlundi 21 avril 2008StatutMembreDernière intervention20 novembre 2011
-
17 févr. 2009 à 14:23
bigfish_le vrai
Messages postés1835Date d'inscriptionvendredi 13 mai 2005StatutMembreDernière intervention20 novembre 2013
-
17 févr. 2009 à 16:36
Bonjour forum,
Est-ce que qq1 de vous connaîtrez le bout de code VBA pour dire :
Pour tous les fichiers de tel dossier faire
1) lire le nom du fichier
2) Si une partie de ce nom comporte un "OK" alors ........
J'ai cela :
Set fs = CreateObject("Scripting.FileSystemObject")
Set rep = fs.getfoleder("repertoire_du_dossier")
For Each fileitem In rep
MsgBox (fileitem.Name)
Next
cs_Jack
Messages postés14006Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201578 17 févr. 2009 à 15:14
+ il faut déclarer FileItem :
Dim mFichier As File ' 'mFichier' à la place de FileItem
+ Ne donne pas à tes variables des noms qui pourraient ressember à des instructions ou objets, comme FileItem : Le compilateur pourrait avoir du mal à interpréter = bug
Pour ton test :
If mFichier.Name Like "*OK*" Then ...
bigfish_le vrai
Messages postés1835Date d'inscriptionvendredi 13 mai 2005StatutMembreDernière intervention20 novembre 201314 17 févr. 2009 à 16:36
Bonjour,
une autre methode,
Sub bil()
Dim PartFileName As String, FichierTrouve() As String, NbFiles As Long, i As Long, FolderPath As String
PartFileName = "OK"
FolderPath = "c:\mon repertoire test"
With Application.FileSearch
.NewSearch
.LookIn = FolderPath 'Look in path
.Filename = PartFileName 'all files that contain this string will be selected
.SearchSubFolders = False
.Execute
NbFiles = .FoundFiles.Count 'how many files ?
If NbFiles = 0 Then 'if finally no file found
MsgBox "Cannot find any file. Please, check the path specified. ", vbCritical, "Files error..."
Exit Sub
End If
ReDim ThemFiles(NbFiles) 'we dimension the table according the file(s) number
For i = 1 To NbFiles 'for each files found
MsgBox Dir(.FoundFiles(i))
Next i
.LookIn = ""
End With
End Sub