|
请参考:
- Sub 修改文件名()
- Dim Fso As Object, Folder As Object, s$
- s = [b1]
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(ThisWorkbook.Path)
- Call GetFiles(Folder, s, True)
- MsgBox "文件名修改完毕"
- Set Folder = Nothing
- Set Fso = Nothing
- End Sub
- Sub 恢复文件名()
- Dim Fso As Object, Folder As Object, s$
- s = [b1]
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Folder = Fso.GetFolder(ThisWorkbook.Path)
- Call GetFiles(Folder, s, False)
- MsgBox "文件名恢复完毕"
- Set Folder = Nothing
- Set Fso = Nothing
- End Sub
- Sub GetFiles(ByVal Folder As Object, s$, f As Boolean)
- Dim SubFolder As Object
- Dim File As Object
- If Folder.Path <> ThisWorkbook.Path Then
- For Each File In Folder.Files
- If File.Name Like "*.xlsx" Then
- If f Then
- File.Name = Replace(File.Name, ".xlsx", s & ".xlsx") '修改文件名
- Else
- File.Name = Replace(File.Name, s, "") '恢复文件名
- End If
- End If
- Next
- End If
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, s, f)
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|