返回列表 上一主題 發帖

取得資料夾內所有檔案名稱

取得資料夾內所有檔案名稱

請教各位前輩

舉例: 桌面有個AAA資料夾,內含數百個.XLS 或者 .PDF檔案
能否使用vba將資料夾內所有的檔案
取其檔案名稱,將其檔案名稱存於sheet中?
請多指教

謝謝板大
舊家找來的參考資料 ^^"  應用方式再修正一下同樣有效
'====================================
Private Sub CommandButton1_Click()
    Dim P As String
    P = ThisWorkbook.Path '指定資料夾路徑
    ActiveSheet.UsedRange.Offset(1).Clear
    Get_Picture P
End Sub
Private Sub Get_Picture(ByVal P As String)
    Dim Fs, C As Variant
    Set Fs = CreateObject("Scripting.FileSystemObject").GETFolder(P)
    With ActiveSheet
    For Each C In Fs.Files
        If C Like "*.xls" Then '指定副檔名
            .Cells(Application.CountA(.[C:C]) + 1, "C") = C.Name
        End If
     Next
    End With
        For Each C In Fs.SubFolders
            On Error Resume Next
            Get_Picture C
        Next
End Sub
請多指教

TOP

        靜思自在 : 人要自愛,才能愛普天下的人。
返回列表 上一主題