我在文件夹中有大量具有不同名称的excel文件,我需要在.xlsx扩展名之前将-MN附加到所有文件名的末尾。我已经浏览了网络寻找解决方案,但没有找到明确的答案。这是一项工作任务,因此无法下载外部软件。通过命令行或vba宏的东西将是首选。我在导航到正确的文件夹时尝试在命令提示符中使用ren * .xlsx * -MN.xlsx,但它没有产生所需的结果。
这就是我要找的东西:
examplefile.xlsx将成为examplefile -MN.xlsx
我试过了......
ren *.xlsx *-MN.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:\Users\Gary\Desktop\Ex Folder\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(myFilePath)
For Each objFile In objFolder.Files
myFileName = objFile.Name
If Right(myFileName, 4) = ".xlsx" Then
NewFileName = Replace(myFileName, ".xlsx", "-MN.xlsx")
Name myFilePath & objFile.Name As myFilePath & NewFileName
End If
Next objFile
MsgBox "Files Renamed"
End Sub
任何帮助将不胜感激!谢谢!
答案 0 :(得分:0)
Sub RenameFiles()
Dim myFilePath As String, myFileName, NewFileName As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
myFilePath = "C:\Users\Gary\Desktop\Ex Folder\"
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
MsgBox "Files Renamed"
End Sub