• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Rename files from a specific folder

Hi All,

I need to rename around 100 files. Just need to add "2016" after the actual file names. I have done some coding but throwing some error in Save As line.

Please see the attached file.

Thanks and Regards,
Deepak Sharma
 

Attachments

Hi shrivallabha, Yes every file is .csv
Old File Name is = uk_export_Week49.csv
should be replaced by
New File Name = uk_export_Week49_2016.csv

Thanks !!!
 
HI,

I have again try to rename the file name but it's taking file name with extension also & it's saving like this :-
old file name is uk_export_Week23

After running vba code it's saving like :-
uk_export_Week23.csv_2016

this .csv should not come here. file name should be like :-
uk_export_Week23_2016

Please advice ! File attached


Thanks and Regards,
Deepak Sharma
 

Attachments

Hi !​
Code:
Sub Demo4Noob()
    MsgBox Replace("uk_export_Week23.csv", ".csv", "_2016.csv")
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
It's just a sample to show you how to !
See Replace function in VBA inner help, at beginner level, even a child …

I have done some coding
With my sample and after reading help, you will be able to mod your code !

As coding is like fishing, I won't bring you a fish everyday
but I show you how to fish …
 
Also, no need to open files. You can just rename them.

Ex.
Code:
For Each fil In fol.Files
    Name fil.path As Replace(fil.path, ".", "_2016.")
Next fil
 
Back
Top