Excel VBA 列出磁碟機的檔案清單



又是一個使用者需求,所以......分享吧 ^^

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
 
    Dim fls As Object
    Set fls = fso.GetFolder("D:\").Files
 
    Dim i As Integer
    i = 2
 
    With Worksheets("Sheet1")
        .Cells(1, 1).Select
            .Cells(1, 1) = "File Name"
            .Cells(1, 2) = "File Size"
            .Cells(1, 3) = "Date"
            For Each f In fls
                .Cells(i, 1) = f.Name
                .Cells(i, 2) = f.Size
                .Cells(i, 3) = f.DateLastModified
                i = i + 1
            Next
    End With

沒有留言:

張貼留言