This will do that, it stores them in an array then writes it to sheet1
Function GetFileNames()
Dim MyName, MyPath
Dim FNames()
'Find how many file exist
ReDim FNames(0)
MyPath = "C:\" 'You need to change this to your requirement
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
On Error Resume Next
If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
ReDim Preserve FNames(UBound(FNames) + 1)
FNames(UBound(FNames)) = MyPath & MyName
End If
End If
MyName = Dir
Loop
For x = 1 To UBound(FNames)
Sheet1.Cells(x, 1) = FNames(x)
Next x
End Function
--
Message posted via
http://www.officekb.com