hi
I face problem with this code . it should rename the files based on the columns .
first the code matches names are existed into headers with the directory and rename the files but it just works in subfolder contains files extensions .PDF and show error "subscript out of range" in this line
OldName = MYPATH & FileExt & "\" & FileList(i - 1)
this is the whole code
Sub rename5()
Const MYPATH As String = "C:\Users\LP PC\Desktop\fl\"
Dim LastCol As Integer, LastRow As Long
Dim i As Integer, j As Integer
Dim NewName As String, FileExt As String, OldName As String
Dim FileName As String, FileList() As String, lCount As Long
LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For j = 1 To LastCol
LastRow = ActiveSheet.Cells(Rows.Count, j).End(xlUp).Row
FileExt = Cells(1, j).Value
lCount = 0
FileName = Dir(MYPATH & FileExt & "\")
While Len(FileName) > 1
lCount = lCount + 1
ReDim Preserve FileList(1 To lCount)
FileList(lCount) = FileName
FileName = Dir()
Wend
For i = 2 To LastRow
NewName = MYPATH & FileExt & "\" & Cells(i, j).Value & "." & FileExt
OldName = MYPATH & FileExt & "\" & FileList(i - 1)
Name OldName As NewName
Next i
Next j
MsgBox "Done!"
End Sub