Sub RenameFilesInFolder()
Dim folderPath As String
Dim filePath As String
Dim newFileName As String
Dim fileNames As String
Dim fileCount As Long
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
folderPath = "C:\SomePath\" ' <-- Change this as appropriate
newFileName = Range("A1").Value ' <-- Change the range as appropriate
fileCount = 0
filePath = Dir$(folderPath & "*.*")
Do While filePath <> ""
fileCount = fileCount + 1
fileNames = fileNames & filePath & "," & newFileName & CStr(fileCount) & "." & fso.GetExtensionName(filePath) & ","
filePath = Dir$
Loop
Dim renameFiles() As String
renameFiles = Split(fileNames, ",")
For fileCount = 0 To UBound(renameFiles) - 2 Step 2
Name folderPath & renameFiles(fileCount) As folderPath & renameFiles(fileCount + 1)
Next
End Sub
Sub RenameFilesInFolder()
Dim folderBrowser As Object
Dim folderPath As String
Dim filePath As String
Dim newFileName As String
Dim fso As Object
Dim wb As Workbook
Set folderBrowser = CreateObject("Shell.Application").BrowseForFolder(0, "", 0)
If folderBrowser Is Nothing Then Exit Sub
Set fso = CreateObject("Scripting.FileSystemObject")
folderPath = folderBrowser.Self.Path & "\"
Application.ScreenUpdating = False
filePath = Dir$(folderPath & "*.xls*")
Do While filePath <> ""
Set wb = Workbooks.Open(folderPath & filePath)
If wb.Sheets.Count > 1 Then
newFileName = wb.Sheets(2).Range("B2").Value
Else
newFileName = ""
End If
wb.Close False
If newFileName <> "" Then
Name folderPath & filePath As folderPath & newFileName & "." & fso.GetExtensionName(filePath)
End If
filePath = Dir$
Loop
Application.ScreenUpdating = True
End Sub