Rename Files in a Folder and Overwrite if File Exists
Hi
I have a macro that renames all files in a folder that begin with the litter "I":
Sub RenameFile()
Dim file
Dim path As String
path = "C:\DOCUMENTS\FOLDER"
file = Dir(path & "I*.docx")
'rename the files with the I in front to remove the I
Dim NewName As String
Do While file <> ""
NewName = Mid(file, 2)
Name path & file As path & NewName
file = Dir()
Loop
End Sub
This works well and does what I expect, however, if the NewName file already exists, I just get an error that it already exists.
Can someone please help with extra code which will overwrite the NewName file if it already exists in the folder.
Thank you very much
|