Giving names to Windows7 files according to a list in excel

Topher

New Member
Joined
Sep 14, 2010
Messages
29
Is there a way that I can rename a lot of files in a snap? :confused:

Like if I had a list of 300 file names that I would like to apply to 300 templates in a folder...

It would be even nicer if I could apply another column to another file detail... say "subject", "year", "category", or "details", etc.
But the Filename is first and foremost...

I want to be able to do it every once and while, because I know live updating would increase difficulty, and probably performance and is just not necessary.
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Here is some code
Code:
'=============================================================================================
'- BULK RENAME FILES IN A FOLDER
'=============================================================================================
'- METHOD
'- 1. GET_FILES MACRO  : GETS FILE NAMES FROM SELECTED FOLDER INTO WORKSHEET COLUMN A
'- 2. MANUAL           : PUT NEW NAMES INTO WORKSHEET COLUMN B
'- 3. SAVE_FILES MACRO : COPIES FILE WITH NEW NAME TO SELECTED FOLDER. DELETES THE OLD FILE
'-    If there is no new name in column B there is no action.
'- Brian Baulsom June 2006
'=============================================================================================
Const FromFolder As String = "F:\TEST\"
Const ToFolder As String = "F:\TEST\"
'---------------------------------------------------------------------------------------------
Dim ws As Worksheet
Dim MyRow As Long
Dim LastRow As Long
Dim FromFile As String
Dim ToFile As String
'=============================================================================================
'- GET FILE NAMES TO WORKSHEET
'=============================================================================================
Sub GET_FILES()
    '-----------------------------------------------------------------------------------------
    Set ws = ActiveSheet
    With ws
        .Range("A:B").Cells.ClearContents
        .Range("A1:B1").Value = Array("FROM", "TO")
        .Range("A2:B2").Value = Array(FromFolder, ToFolder)
        MyRow = 3
    End With
    '----------------------------------------------------------------------------------------
    '- GET FILE NAMES
    FromFile = Dir(FromFolder & "*.*")
    Do While FromFile <> ""
        ws.Cells(MyRow, "A").Value = FromFile
        MyRow = MyRow + 1
        FromFile = Dir
    Loop
    '----------------------------------------------------------------------------------------
    MsgBox ("Done")
End Sub
'============================================================================================
 
'=============================================================================================
'- RENAME FILES
'=============================================================================================
Sub RENAME_FILES()
    '-----------------------------------------------------------------------------------------
    rsp = MsgBox("About to rename files. OK to proceed ?", vbOKCancel)
    If rsp = vbCancel Then Exit Sub
    '-----------------------------------------------------------------------------------------
    Set ws = ActiveSheet
    LastRow = ws.Range("A65536").End(xlUp).Row
    For MyRow = 3 To LastRow
        Application.StatusBar = MyRow & "\" & LastRow
        With ws
            If .Cells(MyRow, "B").Value <> "" Then
                FromFile = FromFolder & .Cells(MyRow, "A").Value
                ToFile = ToFolder & .Cells(MyRow, "B").Value
                FileCopy FromFile, ToFile
                Kill FromFile
            End If
        End With
    Next
    '-----------------------------------------------------------------------------------------
    MsgBox ("Done")
    Application.StatusBar = False
End Sub
'=============================================================================================
 

Forum statistics

Threads
1,082,151
Messages
5,363,449
Members
400,737
Latest member
vipamuk

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top