#1
|
|||
|
|||
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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error Handler If User Does Not Want to Overwrite File | ChrisOK | Excel Programming | 4 | 04-03-2020 08:31 PM |
Need excel macro which helps to rename the files within the folder | ganesang | Excel Programming | 1 | 02-04-2019 11:13 PM |
need to overwrite folder permissions from previous office version | gmee | Outlook | 0 | 02-19-2018 10:06 AM |
Normal file already exists | cryptogram | Word | 2 | 09-21-2015 08:56 PM |
Word does not ask do i want to overwrite a file on saving a file | sam2149 | Word | 2 | 03-24-2014 04:18 AM |