Consulting

Results 1 to 14 of 14

Thread: Paste the file names in a excel sheet

  1. #1
    VBAX Regular
    Joined
    Feb 2012
    Posts
    46
    Location

    Paste the file names in a excel sheet

    Hi

    I have plenty of files in a folder path E:\SETHU-OFFICIAL. The files are around 500. So now i want to paste the file names in a excel sheet, which are in E:\SETHU-OFFICIAL folder. i also saved a excel sheet in E:\ called files.xls.

    Please help me.

  2. #2
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    Try this

    [vba]

    Dim i As Long
    Dim Fi_Name As String
    Fi_Name = Dir("E:\SETHU-OFFICIAL\*.xls")
    i = 1
    Do Until Fi_Name = ""
    Cells(i, 1).Value = Fi_Name
    i = i + 1
    Fi_Name = Dir
    Loop
    [/vba]

  3. #3
    VBAX Regular
    Joined
    Feb 2012
    Posts
    46
    Location
    Where should i paste this and how to run this.

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location

    David


  5. #5
    VBAX Regular
    Joined
    Feb 2012
    Posts
    46
    Location
    Thanks

  6. #6
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    how do you make this list files from sub folders too?
    and how do you limit to a specific filer type?
    I have swf and pdf, but only want pdf listed
    [VBA]

    Sub GetFileNames()

    Dim xRow As Long
    Dim xDirect$, xFname$, InitialFoldr$

    InitialFoldr$ = "C:\Users\Mark\Documents\Right To Know_edit\msds" '<<< Startup folder to begin searching from

    With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = Application.DefaultFilePath & "\"
    .Title = "Please select a folder to list Files from"
    .InitialFileName = InitialFoldr$
    .Show
    If .SelectedItems.Count <> 0 Then
    xDirect$ = .SelectedItems(1) & "\"
    xFname$ = Dir(xDirect$, 7)
    Do While xFname$ <> ""
    ActiveCell.Offset(xRow) = xFname$
    xRow = xRow + 1
    xFname$ = Dir
    Loop
    End If
    End With
    End Sub
    [/VBA]

  7. #7
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location

    David


  8. #8
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location

    searching files in subfolders hangs

    Thank you David:
    I ran this to find all .pdf files 2 folders levels down
    and even tried 1 level down, it errors on
    [VBA]With Application.FileSearch[/VBA]
    microsoft Visual Basic message:
    run time error '445'
    object does not support this action

    not sure if its because im looking for .pdf not an office file?
    or more than 1 folder deep?

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,098
    Location
    What version of Excel are you running?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Quote Originally Posted by mperrah
    it errors on
    My apologies, I keep forgeting M$ took FileSearch out starting in 2007.

    Search for 'directory list excel -filesearch'

    David


  11. #11
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location

    Wink 2010

    running 2010 on win 7 x64

  12. #12
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,098
    Location
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  13. #13
    VBAX Regular
    Joined
    Feb 2012
    Posts
    46
    Location
    Yes attached file is working. But i want file names of the sub folder name and file name also.


    In E drive ive one folder named SETHU-OFFICIAL, There are 15 files and one more folder with named ramu. Inside the ramu folder Ive 60 files

    if im extracting SETHU-OFFICIAL folder.it is showing 15 files itself.
    It has extract the ramu folder placed inside SETHU-OFFICIAl also, The ramu folder file names also required. Any body can help me?
    Attached Files Attached Files

  14. #14
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,098
    Location
    Have a look here http://www.mrexcel.com/forum/showthr...?p=64850#66157 and in particular at posts 6, 8 & 9.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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