|
先批量获取原文件名,再改名,你的原始表中路径也不完整,我给你模拟了一下。- Public jg(), khm&, tms# '
- Private Fso As Object, myPath As String
- Sub 选择要批量重命名文件的文件夹()
- Dim Fo, SHT As Worksheet
- Sheets("修改文件名").Activate
- Sheets("修改文件名").Range("A1").Value = "原始路径"
- Sheets("修改文件名").Range("b1").Value = "原文件名"
- Sheets("修改文件名").Range("c1").Value = "新文件名"
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择要提取与导入或重命名的图片或文件所在的文件夹"
- .Show
- If .SelectedItems.Count = 0 Then Exit Sub
- myPath = .SelectedItems(1) & ""
- End With
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Fo = Fso.getfolder(myPath)
- Call 递归(Fo)
- End Sub
- Sub 获取文件名(Folder)
- Dim Fi, filename As String, r As Integer
- For Each Fi In Folder.Files
- r = Range("A65536").End(xlUp).Row + 1
- filename = Fi.Name
- Cells(r, 1) = Folder.path & ""
- Cells(r, 2) = Fso.getbasename(filename)
- Cells(r, 4) = "." & Fso.GetExtensionName(filename)
- r = r + 1
- Next
- End Sub
- Sub 递归(Folder)
- Dim Fi, Fo
- Call 获取文件名(Folder)
- If Folder.subfolders.Count > 0 Then
- For Each Fo In Folder.subfolders
- Call 递归(Fo)
- Next
- End If
- End Sub
- Sub 文件批量重命名()
- On Error Resume Next
- Dim i As Integer, r As Integer, rng As Range
- r = Range("A65536").End(xlUp).Row
- For Each rng In Range("C2:C" & r)
- If rng = "" Then MsgBox "请将新文件名填写完整!", 64, "提示": Exit Sub
- Next
- For i = 2 To Range("A65536").End(xlUp).Row
- Name Cells(i, 1) & Cells(i, 2) & Cells(i, 4) As Cells(i, 1) & Cells(i, 3) & Cells(i, 4)
- Next
- MsgBox "文件名修改完成,请到文件所在文件夹查看!", 64, "提示"
- End Sub
- <b>
- </b>
复制代码
新建文件夹 (2).rar
(59.81 KB, 下载次数: 38)
|
|