码迷,mamicode.com
首页 > 编程语言 > 详细

20170906xlVBA_RecursionGetFiles

时间:2017-09-06 21:24:30      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:logs   info   this   vba   get   folders   debug   efi   报表   

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

标签:logs   info   this   vba   get   folders   debug   efi   报表   

原文地址:http://www.cnblogs.com/nextseven/p/7486836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!