Renaming the multiple workbooks on the bases of their respective cell value

Cloud67

New Member
Joined
Mar 13, 2019
Messages
20
Hi,
I receive around 300 files through a software that i use in my office. The problem is that the software saves the files on my computer with the weird name which is meaning less. I would like to save those files with the account number which is located in each file in specific cell (different account number for different file ). Is there any way i could achieve that through macro? I would greatly appreciate the help.
Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Use the following macro.
The macro will take the name of the first page of the book, from cell C2.
Change the data in red for your current data


Code:
Sub rename_books()
    Dim books As Variant
    Dim wPath As String, wName As String, wExt As String
    Dim wb2 As Workbook
    
    Application.ScreenUpdating = False
    wPath = "[COLOR=#ff0000]C:\trabajo\books\[/COLOR]"
    If Right(wPath, 1) <> "\" Then wPath = wPath & "\"
    
    books = Dir(wPath & "*.xls*")
    Do While books <> ""
        Set wb2 = Workbooks.Open(wPath & books)
        wName = wb2.Sheets(1).Range("[COLOR=#ff0000]C2[/COLOR]").Value
        If wName <> "" Then
            wName = Replace(wName, "/", "-")
            wExt = Mid(books, InStrRev(books, ".") + 1)
            wb2.Close False
            Name wPath & books As wPath & wName & "." & wExt
        End If
        books = Dir()
    Loop
    MsgBox "End"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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