Results 1 to 11 of 11

Thread: Select a few files in a folder

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Select a few files in a folder

    Dear All,

    I wanted to select a few excel workbooks e.g. 3 out of 10 in a folder. How do i write the macro to do it?

    example;

    i have 20 workbooks in the same folder with same template. But, i wanted to select only 15 by highlighting the files that i need while the other 5 i do not want.

    Thanks
    NoobAvenger

  2. #2
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    Re: Select a few files in a folder

    What do you mean? Where are you selecting the 15 files? Are you wanting a file dialog box, or are you going to have a list within a workbook/other program where you select which ones you want?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select a few files in a folder

    But, i wanted to select only 15 by highlighting the files that i need
    where, how?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Smile Re: Select a few files in a folder

    Sorry for not explain it clearly.

    This is my code for grabbing all files in one folder.

    Code:
    mypath = InputBox("Please enter path of the file location!", "Path")
    fname = Dir(mypath & "\" & "*.xls")
    Do While Len(fname) > 0
    Set wb = Workbooks.Open(mypath & "\" & fname)
    
    ' i do all my stuff here....
    
    wb.Activate
    wb.Close
    fname = Dir
    
    Loop
    This code does not allow me to select a few specific files.

    What I wanted to do now is that I want to get prompted by the Directory Box and then I can choose a few files manually from there.

    Thanks for replying.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select a few files in a folder

    i think application.filesearch is what you want, displays a dialog and returns a list of files to loop through
    Last edited by westconn1; Apr 26th, 2011 at 03:22 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Re: Select a few files in a folder

    Hi westconn,

    I'm not sure how to use application.filesearch

    Would appreciate if you can explain it to me. Thanks a lot. sorry for trouble

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select a few files in a folder

    my error, filesearch does not display a dialog, there is an application object that does, but it is not available in excel 2000, you will have to checkout in version 2003
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Lively Member Vanquish2888's Avatar
    Join Date
    Sep 2007
    Posts
    104

    Re: Select a few files in a folder

    vb Code:
    1. Dim FileLocationArray As Variant
    2.  
    3. FileLocationArray = Application.GetOpenFilename("Excel Files,*.xls", 1, "Select Multiple Files", , True)
    4. For i = LBound(FileLocationArray) To UBound(FileLocationArray)
    5.     Application.Workbooks.Open FileLocationArray(i)
    6. Next i

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select a few files in a folder

    doh!! you think i could remember getopenfilename?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    20

    Re: Select a few files in a folder

    i've tried it and it is really what i wanted but how do i open one workbook at a time and do all the stuff that i want and then close it then open then next workbook?

    sorry for trouble..

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select a few files in a folder

    modify you code in post #4 to work with vanquishes code in post #7, use his for loop rather than your do loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width