I have a script that looks at Column A for the old file name and compares it to a bunch of images in a folder, when it finds a match it then looks in Column B for the new file name and renames the files.. That works great except when the new file name is the same as the current and it generates a "Run-time error '58' File already exists"
How do I get it to ignore or rename anyway?
Sub renameFiles()
Dim FSO, objFolder, Folder, LR As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\images") 'here set your directory of images'
LR = [a65536].End(xlUp).Row
For Each file In Folder.Files
For i = 1 To LR
If file.Name Like Cells(i, 1) & ".tif" Then file.Name = Cells(i, 2) & ".tif"
Next i
Next file
End Sub
Thanks
Tom
How do I get it to ignore or rename anyway?
Sub renameFiles()
Dim FSO, objFolder, Folder, LR As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder("C:\images") 'here set your directory of images'
LR = [a65536].End(xlUp).Row
For Each file In Folder.Files
For i = 1 To LR
If file.Name Like Cells(i, 1) & ".tif" Then file.Name = Cells(i, 2) & ".tif"
Next i
Next file
End Sub
Thanks
Tom