|
-
- Sub 批量修改文件夹内Word文档名称()
-
- Dim folderPath As String
- Dim file As String
- Dim name As String
- Dim dialog As FileDialog
- Dim n, i
-
- Set dialog = Application.FileDialog(msoFileDialogFolderPicker)
-
- ' 打开文件夹选择对话框
- With dialog
- .Title = "选择文件夹"
- .AllowMultiSelect = False
- If .Show <> -1 Then
- MsgBox "未选择文件夹!"
- Exit Sub
- Else
- folderPath = .SelectedItems(1)
- End If
- End With
-
- i = 0
- ' 遍历文件夹中的所有文件
- file = Dir(folderPath & "\*.*")
- Do While file <> ""
- ' 如果是Word文件,则进行重命名
- If InStr(1, LCase(file), ".doc") > 0 Or InStr(1, LCase(file), ".docx") > 0 Then
- name = file
- name = Replace(name, "模板", "模板二号")
- Name folderPath & "" & file As folderPath & "" & name
- i = i + 1
- End If
- file = Dir
- Loop
-
- MsgBox i & "个文件重命名完成!"
- End Sub
复制代码
|
|