VB Code for getting all the files names in a folder

  • Thread starter Thread starter Gokul
  • Start date Start date
G

Gokul

Hai all,
I need to write an Excel Macro to read a folder's content and to save
the filenames in an array of strings. But I dont know the commands to
use. Please help me with an idea. If possible, give a sample code
also.

Thanks,
Gokul
 
Gokul said:
I need to write an Excel Macro

VB.NET is a new programming language which is not related to Excel VBA. You
will more likely get an answer in this group:

<URL:
 
Hai all,
I need to write an Excel Macro to read a folder's content and to save
the filenames in an array of strings. But I dont know the commands to
use. Please help me with an idea. If possible, give a sample code
also.

Thanks,
Gokul

Try this macro in Excel,
Sub DirLoop()

Dim MyFile As String, Sep As String
Dim i As Integer

Sep = Application.PathSeparator
i = 1

Application.GetOpenFilename

MyFile = Dir(CurDir() & Sep & "*.*")

' Starts the loop, which will continue until there are no more
files found.
' Searches current directory only
Do While MyFile <> ""
'MsgBox CurDir() & Sep & MyFile
Range("A" & i).Value = MyFile

i = i + 1
MyFile = Dir() 'Get Next file
Loop

End Sub
 
Back
Top