20170906xlVBA_RecursionGetFiles

Posted Excel VBA 小天地

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20170906xlVBA_RecursionGetFiles相关的知识,希望对你有一定的参考价值。

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

  

以上是关于20170906xlVBA_RecursionGetFiles的主要内容,如果未能解决你的问题,请参考以下文章

20170906xlVBA_CopyDataAndFormatFromSheets

校内集训(20170906)

20170906-多线程之ThreadLocal

20170906 - XML基础 - A

20170906 - XML基础 - Q

20170906模拟赛