Results 1 to 6 of 6

Thread: Macro to list files then Rename them

  1. #1

    Macro to list files then Rename them



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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
    Attached Files Attached Files

  2. #2
    Acolyte patel's Avatar
    Join Date
    Feb 2014
    Location
    Italy
    Posts
    59
    Articles
    0
    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

  3. #3

  4. #4
    Quote Originally Posted by p45cal View Post
    Cross posts:
    any problem if i already have the same post in other forums?

  5. #5
    Quote Originally Posted by patel View Post
    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

  6. #6
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,480
    Articles
    0
    Excel Version
    365
    Quote Originally Posted by boss1982 View Post
    any problem if i already have the same post in other forums?
    Possibly for you later when people get to know: http://www.excelguru.ca/content.php?...-cross-posters

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •