I am trying to copy just the names of a file from a directory and patse it into different cell within excel. I don't need anything from with-in the file. I just need the name of the file. Can anyone Help?
Returns a String representing the [blue]name of a file[/blue], directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.
Public Sub ListAllFiles()
Dim FName As Variant
Dim i As Integer
i = 0
FName = Dir("C:\My Documents\*.xls", vbNormal)
While FName <> ""
i = i + 1
ActiveSheet.Cells(i, 1).Value = FName
FName = Dir()
Wend
End Sub
Note that, as coded, the macro only lists xls files in the nominated folder. To get a different file type, change the 'xls' in the code to suit (use '*.*' for all files).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.