Rename Files Using VBA (Easy Examples)

PHOTO EMBED

Fri Feb 07 2025 08:40:27 GMT+0000 (Coordinated Universal Time)

Saved by @acassell

Sub RenameMultipleFiles()
Dim ws As Worksheet
Dim FolderPath As String
Dim oldFileName As String
Dim newFileName As String
Dim lastRow As Long
Dim i As Long
Set ws = ActiveSheet
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow
oldFilePath = ws.Cells(i, 1).Value & "\" & ws.Cells(i, 2).Value
newFilePath = ws.Cells(i, 1).Value & "\" & ws.Cells(i, 3).Value
If Dir(oldFilePath) <> "" Then
    Name oldFilePath As newFilePath
Else
    MsgBox "File was not found: " & oldFilePath
End If
Next i
MsgBox "Files renaming complete"
End Sub
content_copyCOPY

https://trumpexcel.com/excel-vba/rename-files/