|
按你的要求做了修改。同时做了写补充,在运行前你可以选择需要修改文件名的文件夹。附件稍后上传。
Sub 提取所有文件名()
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
dz = fd.SelectedItems(1)
Else
MsgBox "未选择文件夹"
Exit Sub
End If
With ThisWorkbook.Sheets(1)
.[a1] = "原文件名"
.[b1] = "原文件路径"
.[c1] = "新文件名"
.Range("a2:b" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).Clear
End With
'dz = ThisWorkbook.Path
遍历 (dz)
End Sub
Sub 遍历(x)
Dim fd1 As Folder, fd2 As Folder, f As File
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = ThisWorkbook.Sheets(1)
Set fd1 = fso.GetFolder(x)
For Each f In fd1.Files
If Not f.Name Like "*" & ThisWorkbook.Name & "*" Then
hh = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
ws.Range("A" & hh) = f.Name
ws.Range("B" & hh) = fd1 & "\" & f.Name
'Name ws.Range("a" & hh).Value As ws.Range("a" & hh).Offset(0, 1).Value
End If
Next f
For Each fd2 In fd1.SubFolders
遍历 (fd2)
Next fd2
End Sub
Sub 修改文件名()
Set ws = ThisWorkbook.Sheets(1)
hh = ws.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To hh
Name ws.Range("b" & i).Value As ws.Range("b" & i).Offset(0, 1).Value
Next
End Sub
|
评分
-
1
查看全部评分
-
|