+ Reply to Thread
Results 1 to 3 of 3

Help on VBA loop to open workbook, copy/paste to master workbook, close, and then next.

  1. #1
    Registered User
    Join Date
    06-08-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2003
    Posts
    12

    Help on VBA loop to open workbook, copy/paste to master workbook, close, and then next.

    Hey Guys

    I'm still new to VBA and I've run into some trouble with a loop I've been writing.

    What I basically need it to do is this:

    I have a master file from which I run the VBA. Then I have 20 worksheets, which all corresponds in name to 20 workbooks (Excel-files) that are placed in the same folder as the master file.

    What I need the VBA code to do, is to open each of the workbooks, copy/paste two distinct areas / ranges from that open workbook to the master file (the copy and paste area is the same), and then close all those other workbooks again.

    Fairly simple.

    But I simply can't get it to work.

    Here is the code so far:

    Please Login or Register  to view this content.
    It seems that the issue is generated when trying to open the different files. It's like it doesn't recognize the "\" and instead tries to open an xls file with the name of the folder the files are in + the 1, then 2, then 3, etc.

    If any of you can figure out what the problem is. I would greatly appreciate it!

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    08-03-2005
    Location
    Harpers Ferry, WV
    Posts
    26

    Re: Help on VBA loop to open workbook, copy/paste to master workbook, close, and then next

    Replace your open statement with:
    Workbooks.Open (myPath & filename(ifilename))
    Old Programmers Never Die ... They Just Lose Their Bits

  3. #3
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Help on VBA loop to open workbook, copy/paste to master workbook, close, and then next

    try this (not tested)
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

+ 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