|
每个文件夹单独处理
- Sub AA_修改文件名() '//函数实例
- Dim FileArr, DirArr
- Dim SHX As Worksheet
- Dim I As Long
- Dim OldName, NewName As String
-
- Rem 全部文件夹,含子文件夹
- DirArr = FileAllArr(ThisWorkbook.Path, "*.*", ThisWorkbook.Name, True, True)
- For X = 0 To UBound(DirArr)
-
- Rem 当前文件夹文件,不含子文件夹内文件
- FileArr = FileAllArr(DirArr(X), "*.*", ThisWorkbook.Name, False, False)
-
- For I = 0 To UBound(FileArr)
- OldName = FileArr(I)
- If Len(OldName) > 0 Then
- If IsNumeric(Mid(GetPathFromFileName(FileArr(I), True), 1, 7)) = False Then
- NewName = LastFoledName(FileArr(I), 0, True) & "" & Format(I + 1, "0000000") & GetPathFromFileName(FileArr(I), True)
- Name OldName As NewName
- End If
- End If
- Next
- Next
- End Sub
- Sub AB_恢复文件名() '//函数实例
-
- Dim FileArr, DirArr
- Dim SHX As Worksheet
- Dim I As Long
- Dim OldName, NewName As String
-
- Rem 全部文件夹,含子文件夹
- DirArr = FileAllArr(ThisWorkbook.Path, "*.*", ThisWorkbook.Name, True, True)
- For X = 0 To UBound(DirArr)
-
- Rem 当前文件夹文件,不含子文件夹内文件
- FileArr = FileAllArr(DirArr(X), "*.*", ThisWorkbook.Name, False, False)
-
- For I = 0 To UBound(FileArr)
- OldName = FileArr(I)
- If Len(OldName) > 0 Then
- If IsNumeric(Mid(GetPathFromFileName(FileArr(I), True), 1, 7)) = True Then
- NewName = LastFoledName(FileArr(I), 0, True) & "" & Mid(GetPathFromFileName(FileArr(I), True), 8)
- Name OldName As NewName
- End If
- End If
- Next
- Next
-
- End Sub
复制代码 |
|