Sub 获取所有文件名__后期绑定()
Dim fso As Object, folder As Object, file As Object
Dim i As Integer, folderPath As String
folderPath = "D:\日常审核\新规汇集\新建文件夹" '修改为你的文件夹路径
i = 1 '从第一行开始记录
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderPath)
For Each file In folder.Files
Cells(i, 1).Value = file.Name '文件名写入A列
i = i + 1
Next file
End Sub
Sub 获取文件名_前期绑定()
Dim fso As New Scripting.FileSystemObject
Dim fold As folder, str As String, f As file
str = "D:\日常审核\新规汇集\新建文件夹"
Set fold = fso.GetFolder(str)
For Each f In fold.Filesi = i + 1Cells(i, 1) = f.Name
Next
End Sub
Sub 修改文件名()
str1 = "C:\Users\admin1\Desktop\test.xlsx"
str2 = "D:\日常审核\新规汇集\test_1.xlsx"
Name str1 As str2
'可实现原路径下的重命名,也可以移动(剪切)并重命名
End Sub
Sub 批量修改名称()
Dim str1 As String, str2 As String, oldstr As String, newstr As String
For i = 1 To 99
If Cells(i, 1) <> "" Then
str1 = Cells(i, 1)
str2 = "销售部_" & Left(str1, Application.WorksheetFunction.Find(".", str1)) & "_" & Format(Now, "YY-MM-DD") & Right(str1, Len(str1) - Application.WorksheetFunction.Find(".", str1) + 1)
Cells(i, 2) = str2
oldstr = "D:\日常审核\新规汇集\新建文件夹" & str1
newstr = "D:\日常审核\新规汇集\新建文件夹" & str2
Name oldstr As newstr
End If
Next
End Sub