+ Reply to Thread
Results 1 to 4 of 4

Outputting filenames in excel from a particular

  1. #1
    Bhupinder Rayat
    Guest

    Outputting filenames in excel from a particular

    Hi all,

    I have a folder that contains 200 csv files (i.e. c:\folder). Is there any
    way i can get vba to output the filenames within c:\folder in excel

    i.e. in cell A1 - file.csv
    A2 - file2.csv
    A3 - file3.csv
    etc.................

    Kind Regards,


    Bhupinder.

  2. #2
    chijanzen
    Guest

    RE: Outputting filenames in excel from a particular

    Bhupinder Rayat:

    Try:

    With Application.FileSearch
    rpath = "C:\folder"
    .NewSearch
    .Filename = "*.csv"
    .LookIn = rpath
    .SearchSubFolders = True
    .Execute msoSortByFileName, msoSortOrderAscending
    If .Execute > 0 Then
    For i = 1 To .FoundFiles.Count
    Cells(i, 1) = Dir(.FoundFiles.Item(i))
    Next i
    End If
    End With

    --
    天行健,君*以自強不息
    地勢坤,君*以厚德載物

    http://www.vba.com.tw/plog/


    "Bhupinder Rayat" wrote:

    > Hi all,
    >
    > I have a folder that contains 200 csv files (i.e. c:\folder). Is there any
    > way i can get vba to output the filenames within c:\folder in excel
    >
    > i.e. in cell A1 - file.csv
    > A2 - file2.csv
    > A3 - file3.csv
    > etc.................
    >
    > Kind Regards,
    >
    >
    > Bhupinder.


  3. #3
    Bhupinder Rayat
    Guest

    RE: Outputting filenames in excel from a particular

    chijanzen,

    works like a dream! i can enhance that now to give me exactly what i want.

    Thanks ever so much, have a good day.


    Bhupinder

    "chijanzen" wrote:

    > Bhupinder Rayat:
    >
    > Try:
    >
    > With Application.FileSearch
    > rpath = "C:\folder"
    > .NewSearch
    > .Filename = "*.csv"
    > .LookIn = rpath
    > .SearchSubFolders = True
    > .Execute msoSortByFileName, msoSortOrderAscending
    > If .Execute > 0 Then
    > For i = 1 To .FoundFiles.Count
    > Cells(i, 1) = Dir(.FoundFiles.Item(i))
    > Next i
    > End If
    > End With
    >
    > --
    > 天行健,君*以自強不息
    > 地勢坤,君*以厚德載物
    >
    > http://www.vba.com.tw/plog/
    >
    >
    > "Bhupinder Rayat" wrote:
    >
    > > Hi all,
    > >
    > > I have a folder that contains 200 csv files (i.e. c:\folder). Is there any
    > > way i can get vba to output the filenames within c:\folder in excel
    > >
    > > i.e. in cell A1 - file.csv
    > > A2 - file2.csv
    > > A3 - file3.csv
    > > etc.................
    > >
    > > Kind Regards,
    > >
    > >
    > > Bhupinder.


  4. #4
    Registered User
    Join Date
    09-17-2005
    Location
    Toronto
    Posts
    10
    Wow this works great, is there away to make it return the file name without the file extension.
    Example; "filename.gif" would just be "filename"
    I am putting the data right into an array so even a method to get rid of ".GIF" after would help.

    If you look at the modified sub below I would also like to find away to DIM Scanmaps to the amount of files in the directory, I currently put in 36 to make it work. However if you put in a variable it doesnt work.

    Sub filenames()
    With Application.FileSearch
    rpath = "C:\Program Files\Code2004\MD1"
    .NewSearch
    .Filename = "*.GIF"
    .LookIn = rpath
    .SearchSubFolders = True
    .Execute msoSortByFileName, msoSortOrderAscending
    If .Execute > 0 Then

    Dim Scanmaps(1 To 36) As String

    For i = 1 To .FoundFiles.Count
    Scanmaps(i) = Dir(.FoundFiles.Item(i))
    Next i
    End If
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1