Bonjour,
Je suis débutant en VB. Je veux créér une macro qui affiche le chemin absolu du fichier le plus récent.
En parcourant tous les sous-dossiers.
Bref tout ça fonctionne après des heures de recherche ...
Le problème c'est que je suis obligé de mettre le nom du fichier exact exemple aaaa.txt
C'est un problème pour moi car j'aimerai mettre partiellement le nom du fichier exemple *aa*.txt
Je pense que c'est cette méthode qui est en cause :
Set oFl = p_oFld.Files(p_strFichier & ".txt")
J'aimerai une solution qui me permette de ne pas réécrire tout le code ...
Pouvez-vous m'aider à corriger ce soucis ?
Merci beaucoup
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 Dim tableau() As File Dim cpt As Integer Sub rezerze() cpt = 0 Explorer "aaaaaa", "C:\TestGui" Dim i As Integer Dim monFichierSqlPath As String Dim monFichierSqlDate As String monFichierSqlDate = tableau(0).DateLastModified monFichierSqlPath = tableau(0).Path For i = 0 To cpt - 1 If monFichierSqlDate < tableau(i).DateLastModified Then ' => SI condition validée ALORS monFichierSqlPath = tableau(i).Path monFichierSqlDate = tableau(i).DateLastModified Else ' => SINON 'Instructions si faux End If 'MsgBox tableau(i).Path Next MsgBox monFichierSqlPath End Sub Sub Explorer(p_strFichier As String, p_strCheminDepart As String, Optional p_oFld As Scripting.Folder) On Error GoTo err Dim oFSO As Scripting.FileSystemObject Dim oFld As Scripting.Folder Dim oFl As File Dim fichierdir As String If p_oFld Is Nothing Then 'Instanciation du FSO Set oFSO = New Scripting.FileSystemObject 'Accède au répertoire du départ de recherche 'fichierdir = Dir(p_strCheminDepart & "\" & p_strFichier) Set p_oFld = oFSO.GetFolder(p_strCheminDepart) End If 'fichierdir = Dir(p_strCheminDepart & "\" & p_strFichier) Set oFl = p_oFld.Files(p_strFichier & ".txt") 'probleme ici je ne peux pas mettre aa*.txt cpt = cpt + 1 ReDim Preserve tableau(cpt) Set tableau(cpt - 1) = oFl 'MsgBox oFl.Path 'MsgBox tableau(cpt).Path SubDir: 'Explore les sous-dossiers For Each oFld In p_oFld.SubFolders Explorer p_strFichier, p_strCheminDepart, oFld DoEvents Next oFld fin: Exit Sub err: Select Case err.Number Case 53: Resume SubDir Case Else: MsgBox "Erreur inconnue" Resume fin End Select End Sub
Partager