+ Reply to Thread
Results 1 to 5 of 5

Problem of using VBA to open a list of files and copy to 2 sheets

  1. #1
    Registered User
    Join Date
    01-19-2014
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    12

    Problem of using VBA to open a list of files and copy to 2 sheets

    Now I need to use VBA to a) read all historical excel data files, b) copy all the data from these files to Sheet1 and Sheet2 respectively

    I know how to open a specific file and copy the data, but i dont know how to open various of file without tpying all the files' name into the code.

    Here is the code which i used for reading and copying the historical excel data files.
    Please Login or Register  to view this content.
    Is it only a little adjustment in this code then i can reach my requirement?

    Thanks a lot!


    CROSSPOST LINK: http://www.mrexcel.com/forum/excel-q...-2-sheets.html
    Last edited by JBeaucaire; 03-16-2014 at 09:42 PM. Reason: Leith: Added Code Tags; Jerry: Added crosspost link

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Problem of using VBA to open a list of files and copy to 2 sheets

    You didn't say where the file list is located. This assumes you have full file paths in B2:B? on sheet Report

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-19-2014
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Problem of using VBA to open a list of files and copy to 2 sheets

    Sorry, i forgot to mention the file path.

    the files are locate at, for example, Cell A1, and i type C:\VBA courses\Data Files in cell A1 for locating the files
    Last edited by garyyy3; 03-14-2014 at 11:53 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Problem of using VBA to open a list of files and copy to 2 sheets

    Hi Gary. This is some code I did to open an excel file in my Downloads folder. It opens the file provided you know the main part of the name of the file you're going to open. I use it to open files that have a different date every day after the main name & before the file extension.
    Save an excel file named TestBook.xls to your Downloads folder & run the macro in the attached file. Try it before you put the file in you Downloads folder & after, then try again when the TestBook file is already open. Then close & rename it from TestBook.xls to TestbookAnythingYouLike.xlsx & try again. The code is set to look in the Downloads folder & TestBook is the first part of the file name it looks for, but you can change them to whatever you like.
    Have a play & see if it's of any use to you

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

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

    Re: Problem of using VBA to open a list of files and copy to 2 sheets

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).


    CROSSPOST LINK: http://www.mrexcel.com/forum/excel-q...-2-sheets.html
    ------------------

    I added the crosspost link for you this time, as a courtesy. Please remember in your future posts, or don't do it. This has merely been a harmless warning to underline the importance that you read and follow the Forum Rules we are all expected to abide.

    In case you haven't read these rules you agreed to when you joined, stop and read them now. Thank you for your understanding and compliance.
    _________________
    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!)

+ 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] open list of all .csv files in a folder and copy few colums in a excel of same sheet.
    By gnrao80 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2014, 01:19 AM
  2. Replies: 0
    Last Post: 04-13-2013, 10:45 AM
  3. open files in folder and copy sheets to new workbook
    By matrix_xrs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2013, 06:56 AM
  4. use file list to open files to copy cells over
    By chi11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2012, 12:25 PM
  5. Open/close files and copy and paste problem
    By kb9nvh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2011, 03:30 PM

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