Dim Dic As Object Sub GetFileName() Dim FolderPath As String Set Dic = CreateObject("Scripting.Dictionary") FolderPath = ThisWorkbook.Path & Application.PathSeparator & "2011年报表" RecursionFolder FolderPath Set Rng = ThisWorkbook.Worksheets(1).Range("A1") Rng.Resize(Dic.Count, 1).Value = Application.WorksheetFunction.Transpose(Dic.Items) End Sub Sub RecursionFolder(ByVal FolderPath As String) Dim Fso As Object Dim MainFolder As Object Dim OneFolder As Object Dim OneFile As Object Dim Index As Long Set Fso = CreateObject("Scripting.FileSystemObject") Set MainFolder = Fso.GetFolder(FolderPath) If MainFolder.Files.Count > 0 Then For Each OneFile In MainFolder.Files Index = Dic.Count + 1 Dic(Index) = OneFile.Name Debug.Print Index; OneFile.Name Next End If For Each OneFolder In MainFolder.SubFolders RecursionFolder OneFolder.Path Next Set Fso = Nothing Set MainFolder = Nothing End Sub
时间: 2024-10-07 11:27:49