1. Open the file attached.
2. Run the macro GetFileNames and select the folder containing the files
Path will be imported in column A
File Names will be imported in column B
3. Write the new file name in column C
4. Run the macro ChangeFileNames
This is the Macro that will get the file names & path into excel
Sub GetFileNames()
Dim xRow As Long
Dim oSht As Worksheet
Set oSht = ThisWorkbook.ActiveSheet
Dim xDirect$, xFname$, InitialFoldr$
xRow = oSht.UsedRange.Rows.Count + 1
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
oSht.Range("A" & xRow) = xDirect$
oSht.Range("B" & xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
ThisWorkbook.Save
End Sub
And this one will rename them
Sub ChangeFileNames()
Dim oSht As Worksheet
Set oSht = ThisWorkbook.ActiveSheet
Dim i, r As Integer
Dim strPATH As String
Dim strOLD As String
Dim strNEW As String
Dim strCMD As String
r = oSht.Cells.SpecialCells(xlCellTypeLastCell).Row
If r < 2 Then Exit Sub
On Error Resume Next
With oSht
For i = 2 To r
strPATH = .Range("A" & i)
strOLD = strPATH & .Range("B" & i)
strNEW = .Range("C" & i)
strCMD = "rename " & Chr(34) & strOLD & Chr(34) & " " & Chr(34) & strNEW & Chr(34)
VBA.Shell "C:\Windows\System32\cmd.exe /c " & strCMD, vbHide
Next
End With
End Sub
Please mark the thread as SOLVED if it is.
Bookmarks