+ Reply to Thread
Results 1 to 7 of 7

Copying different excel files in a folder to one excel file as sheets

  1. #1
    Registered User
    Join Date
    06-08-2009
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    4

    Copying different excel files in a folder to one excel file as sheets

    Hi,
    I want to merge(copy) the worksheets in a directory say (C:\Reports) here i have 4 Excel files (A,B,C,D) i want those files in Final.xls as different sheets with A,B,C,D reports. Is there any VBScript to do this? Please help me out.


    Note: But the Name of the sheet in Workbook A is (A.xdo) With some pictures i have
    .xdo is my file getting from Oracle BI Publisher(as .xls) file with sheet name as .xdo.I tried with by changing the .xdo file name to "X" but no luck.

    Thanks and Regards,
    V.Saichand

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying different excel files in a folder to one excel file as sheets

    Try this:

    Please Login or Register  to view this content.
    This macro can be run and it will update an existing report, too, clearing all the old entries and creating an entirely new compilation report from the noted folder.
    Last edited by JBeaucaire; 06-08-2009 at 04:44 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-08-2009
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copying different excel files in a folder to one excel file as sheets

    Thanks JBeaucaire for your reply,I tried with the macro what you sent but getting error...out of range run-time script 9 like that....

    previously i worked with following code the code which you said is not understanding because i don't know Vb script so, please help on this following code is there any way to compact this code with previous one(which u posted)


    Please Login or Register  to view this content.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying different excel files in a folder to one excel file as sheets

    Thanks JBeaucaire for your reply,I tried with the macro what you sent but getting error...out of range run-time script 9 like that....
    Please add the following line ABOVE my macros title line:

    Please Login or Register  to view this content.
    Then, while still in the VBA editor, click on Debug > Compile VBAProject. See if the debugger points out any visible problems with your edits in advance.

    Then run the macro again and when the error pops up (if it does again), be sure to select DEBUG so that it will open the editor and highlight the line of code it is failing on.

    One simple idea, any chance you forgot the final "\" when editing the strPath?

    I ran the module I wrote you multiple times and it seems to work fine, but my sheets are EXACTLY the way you described. Any chance your original specifications were off somehow? Is the sheet needed inside each workbook REALLY called by the exact same name as the workbook plus .xdo?

    You could post a sanitized version of one of the import sheets so I can look at the layout.


    BTW, your macro is pretty much the same exact approach mine uses, you've just got different variable names. It's the same critter.
    Last edited by JBeaucaire; 06-09-2009 at 11:28 AM.

  5. #5
    Registered User
    Join Date
    06-08-2009
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copying different excel files in a folder to one excel file as sheets

    hi,
    i added
    Please Login or Register  to view this content.
    before the macro. i used debug stepin option i am getting error at line

    Please Login or Register  to view this content.
    Error message:
    Run-time error '9'
    subscript out of range


    one quick question where the files are going to save i mean path?

    I uploaded the sample files can you please go through that files!!
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying different excel files in a folder to one excel file as sheets

    Can you zip the file(s) and not rar files.

    The error on the line you've noted means the sheetname does not exist in the workbook that opened. Is that the letter "o" or the number "0" on there? .xdo and xd0 are different things entirely. Verify your sheetnames are what you think they are, the macro works because my sample sheets all have "A.xdo", "B.xdo" sheets in them...

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Copying different excel files in a folder to one excel file as sheets

    As per our Skype conversation, I have removed the "xdo" activation step since each workbook being opened only has one sheet in it, this is an unnecessary step.
    Please Login or Register  to view this content.
    I highlighted the updated lines...
    Last edited by JBeaucaire; 06-10-2009 at 01:48 AM. Reason: edited a few lines to simplify

+ 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