Reputation: 477
I have a large amount of excel files in a folder and I need to append -MN to the end of all the file names. I've looked around the web for a solution but haven't had much luck finding a clear answer.
For example:
examplefile.xlsx would become examplefile -MN.xlsx
Any help would be greatly appreciated! Thank you!
Upvotes: 0
Views: 2310
Reputation: 422
This should work. I changed If Right(myFileName, 5) = ".xlsx" Then to... If Right(myFileName, 4) = ".xlsx" Then
Sub RenameFiles()
Dim myFilePath As String, myFileName, NewFileName As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
myFilePath = "C:\Temp\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(myFilePath)
For Each objFile In objFolder.Files
myFileName = objFile.Name
If Right(myFileName, 5) = ".xlsx" Then
NewFileName = Replace(myFileName, ".xlsx", "-MN.xlsx")
Name myFilePath & objFile.Name As myFilePath & NewFileName
End If
Next objFile
End Sub
Upvotes: 1
Reputation: 241
This should add the suffix (-MN) to all xlsx files present in the folder
Upvotes: 2