Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-16-2021, 04:40 PM
Jayay159 Jayay159 is offline Rename Files in a Folder and Overwrite if File Exists Windows 10 Rename Files in a Folder and Overwrite if File Exists Office 2013
Novice
Rename Files in a Folder and Overwrite if File Exists
 
Join Date: Oct 2021
Posts: 2
Jayay159 is on a distinguished road
Question 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
Reply With Quote
 



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
Rename Files in a Folder and Overwrite if File Exists 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft