Private Declare Function SHCreateDirectoryEx Lib "Shell32.dll" Alias "SHCreateDirectoryExA" _
(ByVal hwnd As Long, ByVal pszPath As String, ByVal lngsec As Long) As Long
Option Explicit
Private Function CreationDossier(sDossier) As Long
Dim Rep As Long
Rep = SHCreateDirectoryEx(0&, sDossier, 0& )
End Function
Private Sub Lire(sDossier As String)
Dim sFichierIn As String, sFichierOut As String
Dim sChaine As String
Dim NumFichier1 As Integer, NumFichier2 As Integer
Dim sCheminIn As String, sCheminOut As String, sExt As String
Dim sDossierOut As String
Close
sDossierOut = ThisWorkbook.Path & "\" & "Filtrés"
CreationDossier sDossierOut
sFichierIn = Dir$(sDossier & "\*.*" )
Do While Len(sFichierIn) > 0
sExt = Right$(sFichierIn, Len(sFichierIn) - InStrRev(sFichierIn, "." ))
sFichierOut = sFichierIn
If UCase$(sExt) = "TXT" Then
sCheminIn = sDossier & "\" & sFichierIn
sCheminOut = sDossierOut & "\" & sFichierOut
NumFichier1 = FreeFile
Open sCheminIn For Input As #NumFichier1
NumFichier2 = FreeFile
Open sCheminOut For Output As #NumFichier2
Do While Not EOF(NumFichier1)
Line Input #NumFichier1, sChaine
If InStr(sChaine, "AZERTY" ) = 0 Then
Print #NumFichier2, sChaine
End If
Loop
Close #NumFichier2
Close #NumFichier1
End If
sFichierIn = Dir$()
Loop
End Sub
Sub SelDossier()
Dim sChemin As String
sChemin = ThisWorkbook.Path
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = sChemin & "\"
.Title = "Sélectionner le Dossier Racine"
.AllowMultiSelect = False
.ButtonName = "Sélection Dossier"
.Show
If .SelectedItems.Count > 0 Then
DoEvents
Lire .SelectedItems(1)
End If
End With
End Sub |