Option Explicit
' Early Binding FSO
Private Sub Remplacer(ByVal sDossier As String)
Dim Fichier As Object
Dim FSO As Object
Dim Chemin As String, sLue As String
Dim ChaineARemplacer As String, Chaine As String
Dim Cpt As Long
Chemin = sDossier & "\"
ChaineARemplacer = ......
Chaine = .......
Set FSO = CreateObject("Scripting.FileSystemObject" )
For Each Fichier In FSO.GetFolder(Chemin).Files
If UCase(Fichier.Name) Like "*.XML" And InStr(Fichier.Name, "Modif_" ) = 0 Then
Cpt = Cpt + 1
With FSO.OpenTextFile(Chemin & Fichier.Name, 1)
sLue = .ReadAll
.Close
End With
sLue = Replace(sLue, ChaineARemplacer, Chaine)
With FSO.CreateTextFile(Chemin & "Modif_" & Fichier.Name, True)
.WriteLine sLue
.Close
End With
End If
Next Fichier
Set FSO = Nothing
Application.StatusBar = "Terminé : " & Cpt & " Fichiers"
End Sub
Sub SelDossier()
Dim sChemin As String
sChemin = ThisWorkbook.Path
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = sChemin & "\"
.Title = "Dossier à traiter"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.ButtonName = "Sélection Dossier"
.Show
If .SelectedItems.Count > 0 Then Remplacer .SelectedItems(1)
End With
End Sub
|