Macro to list files then Rename them

boss1982

New member
Joined
Mar 26, 2014
Messages
10
Reaction score
0
Points
0
hi,

i need ur help pls, i have a macro attached with attached file; it will list the files then will re-name the files based on other cell

example;

Cell A2 = New.mp4
Cell B2 = ggffrr.mp4

so the file
New.mp4 will be renamed to ggffrr.mp4.

it is working fine but the location will be always desktop or documents location

i need from the macro to rename the files and to keep them in the same location

please help
 

Attachments

  • RENAME FILES.xlsm
    24.2 KB · Views: 138
Code:
Sub RenameFile()
    Dim z As String
    Dim s As String
    Dim V As Integer
    Dim TotalRow As Integer
    
    TotalRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    For V = 9 To TotalRow
        z = Cells(V, 2).Value
        s = Cells(V, 4).Value
        
        Dim sOldPathName As String
        sOldPathName = Left(z, InStrRev(z, "\"))
        On Error Resume Next
        Name z As sOldPathName & s
        
    Next V
    
    MsgBox "Congratulations! You have successfully renamed all the files"
    
End Sub
 
Code:
Sub RenameFile()
    Dim z As String
    Dim s As String
    Dim V As Integer
    Dim TotalRow As Integer
    
    TotalRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    For V = 9 To TotalRow
        z = Cells(V, 2).Value
        s = Cells(V, 4).Value
        
        Dim sOldPathName As String
        sOldPathName = Left(z, InStrRev(z, "\"))
        On Error Resume Next
        Name z As sOldPathName & s
        
    Next V
    
    MsgBox "Congratulations! You have successfully renamed all the files"
    
End Sub

thanks a lot....it is working
 
Back
Top