+ Reply to Thread
Results 1 to 18 of 18

Open excel files from chosen folder

  1. #1
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Open excel files from chosen folder

    Hi,

    I have a script that automatically imports all the excel files from a folder and puts them into 1 "master" sheet.
    The 'problem' with this is that the folder is preset in the script.

    Is there a code i can use, that does the same but when you start the macro excel opens a exploror window where you can click a folder where it needs to extract the files from?

    This would make my macro somewhat more dynamic.

    Thanks for all the help.

  2. #2
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Yes, we can do it..
    Can you share the file so that we can add the code to it..
    or u just need a code & you urself will club it?
    Regards
    Parth

    I appreciate your feedback. Hit * if u Like.
    Rules - http://www.excelforum.com/forum-rule...rum-rules.html

  3. #3
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Hi Parth,

    Thank you for your answer. The method i was talking about is in another template and i'm creating a new template for other purposes so i don't have a file yet. But if you could give me the code i can put this in my new file.
    Thank you so much.

  4. #4
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Something like this

    Please Login or Register  to view this content.
    +

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Or just to extract the folder name in

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Thanks man, this is awesome! I will check it out!

  7. #7
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Hi Parth,

    I tried the code + function and changed csv to xls, but it doesn't import the files.
    Since i'm pretty noob at vba, could you take a look?

    I added the file.

    Thanks
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Maybe i was unclear in my question, sorry if this is the case.
    It should move and copy the tabs from the sheets in the folder into the 'master' sheet.

  9. #9
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Hi Crispy, Can you please post the script that automatically imports all the excel files from a folder and puts them into 1 "master" sheet, which you have existing..

    will change the code accordingly then..

    The above script is just an example of folder select..

  10. #10
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Hi Parth,

    Ofcourse,

    See below:

    Please Login or Register  to view this content.
    This excelfile has two sheets. Start: this is like the "terminal" where a command button is to start the macro.
    Consolidate: it takes the items from the several sheets and consolidates this into this sheet.

    For this file it should not consolidate and simple move and copy the sheets into the one file.

    Thank you for all your help
    Last edited by Crispy85; 06-29-2015 at 10:50 AM. Reason: Code fixed

  11. #11
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Here you go.. Check now..

    The Attached file will allow you to select the folder you wish too
    after which it will move all tabs to your source "Import Files" file at the end of sheet3
    Attached Files Attached Files
    Last edited by Parth007; 06-29-2015 at 10:57 AM.

  12. #12
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Hi Parth,

    Cool, thanks!
    I'm checking it now. However it gives me an error

    runtime error 9
    subscript out of range

    on line:

    [CODE][/ ActiveWorkbook.Sheets(x).Copy _
    After:=Workbooks("import files").Sheets(3)CODE]

    this is in the macro Copier4()

  13. #13
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Did you change the file name? It must be due to filename issue..


    "import files" should be file name or else change the file name in code as you did to it..

  14. #14
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: Open excel files from chosen folder

    Hi Crispy,

    Try the attached Workbook that should work for you
    @Parth your solution was not working correctly too cause you used activesheet as reference to the sheet that you want to copy from.
    Problem with that is that as soon as you paste the Sheet to the Sourcefile the source becomes the active sheet and then starts to copy itself.
    This way its copying correctly and the code is a bit more dynamic

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Cool. Both thanks for your efforts!! It works!

    I still have one question however.
    The folder only contains .xls files. So i changed it in the script from xlsx to xls. But now i see that it doesn't import everything. And i see why, some file have extension xls and other have XLS.

    Do you know how to fix this in the script?

  16. #16
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Thanks Loki for clarifications

    Crispy - Added code for xls, XLS, xlsx tooo.. please check now
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Open excel files from chosen folder

    Cool, thanks guru's!

  18. #18
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Open excel files from chosen folder

    Did you check with the source files? are you able to pull all data ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. Open excel files in a folder
    By aavins73 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-27-2014, 12:29 AM
  3. one folder & so many excel files are save, i want name change without open excel files
    By sonu_kumar444 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 03:45 PM
  4. [SOLVED] Open excel files from a folder
    By mmmarks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-28-2012, 10:37 AM
  5. Can't open Excel files from folder
    By Mark in forum Excel General
    Replies: 2
    Last Post: 03-17-2006, 10:10 AM

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