snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub ListAllFileNames()
Dim oFSO As Object
Dim ofolder As Object
Dim ofile As Object
Dim i As Integer
Dim LResult As Date
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set ofolder = oFSO.GetFolder("D:\KPI 2022")
For Each ofile In ofolder.Files
Cells(i + 2, 1) = ofile.Name
i = i + 1
LResult = FileDateTime(ofile)
Cells(i + 1, 2) = LResult
Next ofile
End Sub
You do not have the required permissions to view the files attached to this post.
Sub ListAllFileNames()
Dim oFSO As Object
Dim ofolder As Object
Dim ofile As Object
Dim i As Integer
Dim LResult As Date
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set ofolder = oFSO.GetFolder("D:\KPI 2022")
With ActiveSheet
If .Range("a2").Value = "" Then
i = 2
Else
i = .Range("a" & .Rows.Count).End(xlUp).Row + 1
End If
For Each ofile In ofolder.Files
If Application.CountIfs(.Range("a:a"), ofile.Name) = 0 Then
Cells(i, 1) = ofile.Name
Cells(i, 2) = FileDateTime(ofile)
i = i + 1
End If
Next ofile
End With
End Sub