|
楼主 |
发表于 2014-5-19 13:24
|
显示全部楼层
更改V1.0:替换字符通过参数传入。。。。- Sub Macro1()
- On Error Resume Next
- Dim Fso As Object, Folder As Object
- Dim str1 As String
- Dim str2 As String
- Dim PathSht As String
- With Application.FileDialog(msoFileDialogFolderPicker)
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = False Then Exit Sub
- PathSht = .SelectedItems(1)
- End With
- Set Fso = CreateObject("Scripting.FileSystemObject")
- str1 = "蓝天"
- str2 = "白云"
- Set Folder = Fso.GetFolder(PathSht)
- Call GetFiles(Folder, str1, str2)
- Set Folder = Nothing
- Set Fso = Nothing
- End Sub
- Sub GetFiles(ByVal Folder As Object, str1 As String, str2 As String)
- Dim SubFolder As Object
- Dim File As Object
- For Each File In Folder.Files
- If File.Name Like "*.doc" Then File.Name = Replace(File.Name, str1, str2)
- Next
- For Each SubFolder In Folder.SubFolders
- Call GetFiles(SubFolder, str1, str2)
- Next
- Set SubFolder = Nothing
- End Sub
复制代码 |
|