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
| Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public textetotal As String
Public texte As String
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String, dossier As String
Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = "Choisissez un dossier de destination pour les sauvegardes."
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
dossier = GetDirectory & ""
Else
GetDirectory = ""
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub recherche_fichier()
dossier = GetDirectory("Sélectionner le répertoire de travail")
If dossier = "" Then MsgBox "Fin du programme", vbCritical, "Pas de répertoire selectionné"
If dossier = "" Then End
With Application.FileSearch
.NewSearch
'.RefreshScopes
.LookIn = dossier
.Filename = "TEST.xls"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.Execute
Application.DisplayAlerts = False
For Ctr = 1 To .FoundFiles.Count
nom_fichier = .FoundFiles(Ctr)
Workbooks.Open Filename:=nom_fichier
''''ouverture puis lecture du fichier
Call traitement
Next
End With
Application.DisplayAlerts = True
End Sub |
Partager