FSO ecraser un fichier existant

adjovi7

XLDnaute Junior
Bonjour,
Je fais appelle a vos connaissance pour résoudre une petite macro.
Je dois écraser un fichier existant,mais ma macro me soulève un message erreur fichier déjà présent.
ci joint ma macro pour comprendre ma problématique.
Ma macro bloque sur cette ligne de code ( FSO.MoveFile Source:=FromPath, Destination:=ToPath)

Sub RenameFile()

Dim madate As String
Dim FromPath As String
Dim ToPath As String

'Déclaration des variables
madate = Format(Date, "dd-mm-yyyy")

Set FSO = CreateObject("Scripting.FileSystemObject")
FromPath = "I:\DEVIS\Relance PO SF\Classeur1.xlsx"
ToPath = "I:\DEVIS\Relance PO SF\ATTENTE PO " & "_" & madate & ".xlsx"

If FSO.FileExists(FromPath) = False Then
MsgBox strFile & " doesn't exist"
Exit Sub
End If

If FSO.FileExists(FromPath) = True Then
If dir(ToPath) <> "" Then
FSO.MoveFile Source:=FromPath, Destination:=ToPath

End If

End If
Set FSO = Nothing

End Sub

Cordialement,
Adjovi7
 

Discussions similaires

Statistiques des forums

Discussions
311 720
Messages
2 081 915
Membres
101 837
dernier inscrit
Ugo