将文本附加到文件夹中的多个.xlsx文件的文件名末尾

时间:2021-03-24 19:52:05

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.

我在文件夹中有大量的excel文件,我需要将-MN附加到所有文件名的末尾。我在网上寻找解决方案,但没有太多运气找到一个明确的答案。

For example:

examplefile.xlsx would become examplefile -MN.xlsx

examplefile.xlsx将成为examplefile -MN.xlsx

Any help would be greatly appreciated! Thank you!

任何帮助将不胜感激!谢谢!

2 个解决方案

#1


1  

This should work. I changed If Right(myFileName, 5) = ".xlsx" Then to... If Right(myFileName, 4) = ".xlsx" Then

这应该工作。我改变了如果正确(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

#2


2  

  1. Go to command prompt
  2. 转到命令提示符

  3. Point to the folder location having the files
  4. 指向具有文件的文件夹位置

  5. Type: ren *.xlsx *-MN.xlsx
  6. 输入:ren * .xlsx * -MN.xlsx

This should add the suffix (-MN) to all xlsx files present in the folder

这应该将后缀(-MN)添加到文件夹中存在的所有xlsx文件

#1


1  

This should work. I changed If Right(myFileName, 5) = ".xlsx" Then to... If Right(myFileName, 4) = ".xlsx" Then

这应该工作。我改变了如果正确(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

#2


2  

  1. Go to command prompt
  2. 转到命令提示符

  3. Point to the folder location having the files
  4. 指向具有文件的文件夹位置

  5. Type: ren *.xlsx *-MN.xlsx
  6. 输入:ren * .xlsx * -MN.xlsx

This should add the suffix (-MN) to all xlsx files present in the folder

这应该将后缀(-MN)添加到文件夹中存在的所有xlsx文件