VBA 批量变换文件名
1. 页面布局
在“main”Sheet中按照下面的格式编辑。
2. 实现代码
Private wsMain As Worksheet
Private intIdx As LongPrivate Sub getExcelBookList(strPath As String)Dim fso As ObjectDim objFile As ObjectDim objFolder As ObjectSet fso = CreateObject("Scripting.FileSystemObject")For Each objFolder In fso.GetFolder(strPath).SubFoldersCall getExcelBookList(objFolder.Path)Next objFolderFor Each objFile In fso.GetFolder(strPath).FilesIf Left(objFile.Name, 1) <> "~" ThenwsMain.Cells(intIdx, 3) = strPathwsMain.Cells(intIdx, 4) = objFile.NameintIdx = intIdx + 1End IfNext objFileSet objFile = NothingSet objFolder = NothingSet fso = Nothing
End S