Sub renameExtensions(ByVal theExtension As String)
filePath = ThisWorkbook.Path
Set FsoObj = CreateObject("Scripting.FileSystemObject")
If FsoObj.FolderExists(filePath) = False Then: Exit Sub
i = 0
Set masterFolder = FsoObj.GetFolder(filePath)
For Each myFile In masterFolder.Files
If Not ThisWorkbook.FullName = myFile Then
extExit = FsoObj.getextensionname(myFile)
If UCase(theExtension) = UCase(extExit) Then
FsoObj.MoveFile myFile, "C:\" & i & "." _
& theExtension
i = i + 1
End If
End If
Next
Set FsoObj = Nothing
If i <> 0 Then
MsgBox "The files in " & ThisWorkbook.Path & " were renamed."
Else:
MsgBox "No files were renamed as extension was not found."
End If
End Sub |