Macro to rename files

gmagana2

New Member
Joined
Oct 6, 2009
Messages
12
Hi Everyone,

Here is one for ya...I would like to create a macro that renames a series of ".out" files in a batch and replace the old files with the renamed files. I am new to programming in general and know very little about VB, can someone PLEASE guide me:confused:.

Thanks
 
I tried to use the code originally given by Alluvian. I have mentioned the old and the new file names in column A and B of the excel sheet containing this macro, however I am getting runtime error 53:file not found message.

the debugger says that error is in the line: Name oldfilename As newfilename

the excel sheet header row has been named as oldfilename and newfilename respectively.

will be grateful for guidance on whats happening here.

Did your oldfilename and newfilename include the complete path to those files? If not, that is the source of your error... you cannot use just the filename by itself... if must include the full path to the file.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Did your oldfilename and newfilename include the complete path to those files? If not, that is the source of your error... you cannot use just the filename by itself... if must include the full path to the file.

Yes I did include the complete path of the old file name and also similar path for new file name. eg D:\Test2\oldfilename.jpg and D:\Test2\newfilename.jpg

One issue is that our old file names have two dots eg oldfilename.jpeg.jpg or oldfilename.jpeg.png

the new name will just rename the file from oldfilename.jpeg.jpg to oldfilename.jpg as the .jpeg is additional text which we want to remove.

Thanks for a prompt response
 
Upvote 0
One issue is that our old file names have two dots eg oldfilename.jpeg.jpg or oldfilename.jpeg.png

the new name will just rename the file from oldfilename.jpeg.jpg to oldfilename.jpg as the .jpeg is additional text which we want to remove.
That is not an issue... I just tested it on my computer and the double dots had not effect. The error message you reported indicates the file is not in the path you specified for it, so either you specified the path or filename incorrectly in your code or you do not have an existing file by that name in that path. Double check the file is in that path and double check the spelling of the path and filename in your code.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top