VBA code to rename multiple files

BLaCKouT

New Member
Joined
May 31, 2009
Messages
42
Good morning all,

I've been googling around to piece together a macro for uniformly re-naming files in Windows, but the methods I've found all seem to be different (and also don't do exactly what I need).

In short, I've got several directories containing a lot of pdf files. These files need to be re-named with a prefix (the same prefix for all files).
Example: the file 12345.pdf gets renamed to reissue 12345.pdf, where "reissue" is the prefix to be added to all files in the directory.

Rather than use a 'fixed' macro to perform the task this once, I'd like to pull in variables from cells in Excel, so that the file can be used as a utility for the future, for different locations and with a different prefix (and eventually a suffix, but that's a tweak for another day).

In the past, you've very kindly helped me with a macro that pulls in a list of file names from a fixed directory. This time, as I don't actually need the list to be imported into Excel, it seems like a waste to pull them in if I can just rename the files in a kind of for/next loop.

What I'd like to end up with:
• The working directory is entered into cell A1
• The desired prefix is entered into cell A2
• A macro to be activated which looks in directory A1, and re-names each file in there with the value of A2 at the start.

I'm not asking you folks to write the whole macro for me as such, but can you give me some pointers towards setting the working directory from a cell, and creating the loop that will rename files without pulling a list into Excel?

As always, thank you in advance for your time!
B.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
hello sir,

i cant showing me error, can you please help me to fix this issue and use this Macro file
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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