VB Code for getting all the files names in a folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gokul

    VB Code for getting all the files names in a folder

    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
  • Herfried K. Wagner [MVP]

    #2
    Re: VB Code for getting all the files names in a folder

    "Gokul" <gokulnitt@gmai l.comschrieb:
    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:news://news.microsoft. com/microsoft.publi c.excel.program ming>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • clausson.s@gmail.com

      #3
      Re: VB Code for getting all the files names in a folder

      On Feb 18, 6:17 am, Gokul <gokuln...@gmai l.comwrote:
      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.Pat hSeparator
      i = 1

      Application.Get OpenFilename

      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

      Comment

      Working...