+ Reply to Thread
Results 1 to 3 of 3

Need optimization on Macro that Open too many files

  1. #1
    Registered User
    Join Date
    08-22-2015
    Location
    C.A.B.A. , Argentina
    MS-Off Ver
    MS Office 15 for Mac
    Posts
    2

    Need optimization on Macro that Open too many files

    Hi, i have a macro that open all the files listed on the column A, and extract the information on the last non empty cell on column H on those files, the problem is that when i run it, after like 13 files my excel just crash, that is why i need some optimization to make my macro run smoother.

    Sub Asignar()

    Dim aux As Single
    Dim x As Integer
    Dim VarArchivos(1 To 100) As String
    x = 1
    Worksheets("Sheet1").Activate
    Worksheets("Sheet1").Range("A1").Activate
    ActiveCell.Range("A1").Activate ‘fill the array with the names of the files.
    Do Until ActiveCell.Value = “XXXXXXXXXX" ‘ the last non-empty cell on the column A is “XXXXXXXXXX”
    VarArchivos(x) = ActiveCell.Value
    ActiveCell.Offset(1, 0).Activate
    x = x + 1
    Loop
    For i = 1 To (x - 1) ' Open all the files on the array and extract the information
    Path = Application.ActiveWorkbook.Path
    Workbooks.Open (Path & "/" & VarArchivos(i) & ".xlsx")
    Worksheets("C.C.").Activate
    Worksheets("C.C.").Range("A1").Activate
    'Selection.End(xlDown).Select
    VarArchivos(i) = ActiveCell.Value
    ActiveWorkbook.Close savechanges:=False
    Next i
    Worksheets("Sheets1").Activate
    Worksheets("Sheets1").Range("B1").Activate
    For i = 1 To (x - 1) ‘Fill the column B with he information in the Array.
    ActiveCell.Value = VarArchivos(i)
    ActiveCell.Offset(1, 0).Activate
    Next i
    End Sub

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Need optimization on Macro that Open too many files

    Try it like this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    08-22-2015
    Location
    C.A.B.A. , Argentina
    MS-Off Ver
    MS Office 15 for Mac
    Posts
    2

    Re: Need optimization on Macro that Open too many files

    Thanks... I just made some changes to your code and it still crashes but i found that the problem it's that the macro crash on MAC, on windows runs much more smoother. I think that what make it crash is the open and close loop, that makes the program goes bad and crash.
    Thanks again for the help.

+ 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. macro to open files and copy specific sheet into new workbook (have open files part)
    By dangerdavedsp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2015, 02:23 PM
  2. [SOLVED] Save/Closed only macro related files and leave unrelated files open in excel?
    By rdowney79 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2013, 04:17 PM
  3. Replies: 0
    Last Post: 04-13-2013, 10:45 AM
  4. Replies: 1
    Last Post: 12-17-2012, 03:41 PM
  5. Replies: 3
    Last Post: 04-08-2012, 06:52 PM
  6. A Macro to open 2 linked files copy 3rd files Input sheet
    By barrha0b in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2010, 09:53 PM
  7. Replies: 2
    Last Post: 11-30-2005, 01:55 AM

Tags for this Thread

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