Sub sample1()
Dim i As Long
Dim buf As String
Const fPath As String = "F:¥sample¥"
buf = Dir(fPath)
i = 1
Do While buf <> ""
i = i + 1
Cells(i, 1) = buf
buf = Dir()
Loop
End Sub
(2)「Microsoft Scripting Runtime」にチェックを入れ、[ OK ] をクリックします。
参照設定
コード
Sub sample_fso()
Dim fso As Scripting.FileSystemObject
Dim f As Scripting.File
Dim i As Long
Const fPath As String = "F:¥sample¥"
Set fso = New Scripting.FileSystemObject
i = 2
For Each f In fso.GetFolder(fPath).Files
Cells(i, 1).Value = fso.GetFileName(f.Name)
i = i + 1
Next f
Set f = Nothing
Set fso = Nothing
End Sub
Sub sample2()
Dim i As Long
Dim buf As String
Const fPath As String = "F:¥sample¥"
buf = Dir(fPath & "A" & "*")
i = 1
Do While buf <> ""
i = i + 1
Cells(i, 1) = buf
buf = Dir()
Loop
End Sub