Formula to rename files in a folder

SimonR

New Member
Joined
Mar 14, 2022
Messages
23
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi,

Following my thread Using Excel VBA to rename files in a folder asking how to rename files in a folder using VBA, I am trying to do something similar but the procedure is more complicated.

In the other scenario I simply needed to attach the same prefix to the first 11 characters of the file name. In this case, however, the file name starts with a number which can be any size up to five digits, preceded by an underscore. I need to attach the same prefix "abcde123 " to the number to get the renamed file.

In regular Excel terms, the new file name would be created by the formula ="abcde123 "&left(a1, find("_",a1)-1). How would I use VBA to change the file name (sFileName as in the other thread) the same way?
 

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.
wouldn't a tool like Bulk Rename Utility do this for you?
 
Upvote 0
With respect that's not really helpful and it seems you haven't fully read both this thread and the one I linked to. I already have the VBA code I need to rename files thanks to Joe4's assistance in the other thread, I just need to tweak it so that all the files are renamed in the way I described above. Also it's a useful means of improving my knowledge of VBA.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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