Forum

Rename File Based o...
 
Notifications
Clear all

Rename File Based on Cell Values

4 Posts
3 Users
0 Reactions
403 Views
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

I have a sheet that contains 3 cell values (screenshot below), which I want to be used to rename the files. This macro I found initially had only 2 values, and the path was included on both of these cell values. I want the path to be listed in a separate line, it will, of course be the same for both.

Cell C2 - Path (for BOTH files)
Cell C4 - Existing Filename
Cell C6 - Rename to

Sub VBARenameFileSheetNames()

Name ActiveSheet.Range("C4") As _
ActiveSheet.Range("C6")

End Sub

2023-05-18_09-27-30.png

 
Posted : 19/05/2023 9:34 am
(@keebellah)
Posts: 373
Reputable Member
 

Sub VBARenameFileSheetNames()

'* Sytax is: FileCopy sourceFullName, newFileName

FileCopy ActiveSheet.Range("C2") & ActiveSheet.Range("C4") , ActiveSheet.Range("C2") & ActiveSheet.Range("C6")
Kill FileCopy ActiveSheet.Range("C2") & ActiveSheet.Range("C4")
End Sub

Make sure that the file path contains the final backslash
You will have to add check if target file is not already present and if the sourcefile is present

 
Posted : 20/05/2023 2:05 am
(@debaser)
Posts: 837
Member Moderator
 

You can add the path in:

Name ActiveSheet.Range("C2") & ActiveSheet.Range("C4") As _
ActiveSheet.Range("C2") & ActiveSheet.Range("C6")

 
Posted : 20/05/2023 4:41 am
(@webbers)
Posts: 148
Reputable Member
Topic starter
 

@Velouria,

That works perfectly! I knew the answer was simple, but every attempt I made mailed. Thanks so very much for your help!!!!

 
Posted : 23/05/2023 2:11 pm
Share: