Wednesday, March 7, 2012

How to get all the file names from a folder using excel VBA ?

Dear All,

Today I am starting this blog with a very small VBA script for a useful function.
The below procedure will help you to fetch all the file names from a folder or a specified file type from a folder.

Sub GetFileNames()
Dim FName As String
FName = Dir("C:\YourPath\" & "*.*", vbNormal)
'//you can set this as per your wish e.g. for all .xlsx, you can change as "*.xlsx"//'
i = 1
While FName <> ""
Cells(i, 1).Value = FName
i = i + 1
FName = Dir()
Wend
End Sub

No comments:

Post a Comment