我在文件夹中有大量的excel文件,我需要将-MN附加到所有文件名的末尾。我已经浏览了网络寻找解决方案,但找不到明确的答案却没有多少运气。
例如:
examplefile.xlsx将成为examplefile -MN.xlsx
任何帮助将不胜感激!谢谢!
答案 0 :(得分:2)
这应该将后缀(-MN)添加到文件夹
中的所有xlsx文件答案 1 :(得分:1)
这应该有效。我改变了如果正确(myFileName,5)=" .xlsx"然后......如果正确(myFileName,4)=" .xlsx"然后
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