+ Reply to Thread
Results 1 to 2 of 2

Open multiple files and copy data is slow, code after end of loop not working - help?

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    Open multiple files and copy data is slow, code after end of loop not working - help?

    Sorry, I have very little VBA skills...

    I have a macro that is mostly working, but it is extremely slow and it stalls after completing the Do-While loop... I can't figure out why! Also, this macro calls another subroutine. On its own, the other subroutine is fast, but when it gets called it's very slow.

    Any ideas?

    Here is my code:

    Sub Consolidate_To_One_Workbook()
    Dim folderPath As String
    Dim filename As String
    Dim wb As Workbook

    folderPath = "C:\Stuff\Macrofiles\" '

    If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

    Set OutputBook = Workbooks.Add
    With OutputBook
    .SaveAs filename:="C:\Stuff\Macrofiles\Output.xls"
    End With

    filename = Dir(folderPath & "*.xls")
    Do While filename <> ""
    Application.ScreenUpdating = False
    Set wb = Workbooks.Open(folderPath & filename)

    'Calls my subroutine here to operate on the just-opened workbook
    Call DataGrabber

    wb.Close False
    filename = Dir
    Loop

    Application.ScreenUpdating = True

    Workbooks("Output.xls").Worksheets("Sheet1").Activate
    Columns("A:ZZ").EntireColumn.AutoFit

    End Sub



    Thanks in advance for your help!
    Last edited by hadamhiram; 12-16-2014 at 05:33 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Open multiple files and copy data is slow, code after end of loop not working - help?

    Please Login or Register  to view this content.
    Should be:
    Please Login or Register  to view this content.
    That may be your problem but:



    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. VBA Open and Copy From Multiple Files
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2013, 02:55 AM
  2. Replies: 0
    Last Post: 03-13-2013, 09:08 PM
  3. [SOLVED] Loop Code for Multiple Output Files
    By mytouchsr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2012, 11:45 AM
  4. Open a file and copy data into multiple files
    By ncduke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2010, 09:39 AM
  5. Code to open multiple excel files
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2008, 05:40 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