2014年2月23日 星期日

取出指定 DIRECTORY 內所有 FILENAME

Sub Get_All_Files_in_Dir()
    Dim myFso As Scripting.FileSystemObject
    Dim myFiles As Scripting.Files
    Dim myFile As Scripting.File
    Set myFso = New Scripting.FileSystemObject
              I = 11
    'SET THE FILES NAME
    Set myFiles = myFso.GetFolder(ThisWorkbook.Path).Files
    For Each myFile In myFiles
                   cells(i,1)= myFile.Name
                   I = I + 1
    Next
    Set myFiles = Nothing   'release all
    Set myFso = Nothing
End Sub

註 : 要開用 Microsoft Scripting Runtime 

沒有留言:

張貼留言