Get All Files from a Directory

C

Crazyhorse

Sub fileExcel()
Dim MyFile, MyPath, MyName

MyFile = Dir("C:\My Documents\*xls")
x = 2
Do While MyFile <> ""
ThisWorkbook.Worksheets("Excel").Cells(x, 1).Value = MyFile
MyFile = Dir()
If MyFile <> "" Then
x = x + 1
ThisWorkbook.Worksheets("Excel").Cells(x, 1).Value = MyFile
End If
Loop

End Sub
 
B

Bob Phillips

Sub fileExcel()
Dim MyFile, MyPath, MyName

MyFile = Dir("C:\My Documents\*xls")
X = 1
Do While MyFile <> ""

X = X + 1
ThisWorkbook.Worksheets("Excel").Cells(X, 1).Value = MyFile
MyFile = Dir()
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top