Excel crashes when opening multiple documents

  • Hello all,

    I wrote a macro in a "Summary" workbook, which loops through design documents (where the name of the design document is written in a column of the summary workbook, and each document is denoted by

    Code
    Workbooks(workbookname).Worksheets("Sheet1").Cells(i, 1).Value

    in my code) and fetch some data from each workbook and inserts the value in a cell. Each of the design documents have the same format.

    My problem is that when the macro tries to open the 6th document, excel crashes. I've tried doing this on a seperate machine and the same happens (i think on the other machine it crashed after the 8th document). I then tried adding a button which replaces the loop. Instead of looping, each time the button is pressed it adds the information of the next document, but to no avail it still crashed.

    I tried looking into methods of clearing memory since I suspect that this is the problem.

    My code to follow. The code for the button is the same, less the for loop. I created a class which fetches the relevant data from each document, please let me know if you would like this included.



    Below is the code for the button which includes an attempt to clear the memory:

  • Re: Excel crashes when opening multiple documents


    Hello Rob, thank you for the reply mate.

    Here is my class



    The program physically crashes "Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience ..."
    It then closes, opens back up and displayes a recovered document.

    I forgot to add, when I run the button 5 times, and restart the document, I can add another 5 sets of documents.

    Thank you so much for the help, this proplem is very frustrating.

  • Re: Excel crashes when opening multiple documents


    Maby the leak is in the class methods which loops through the columns of the external sheets? I do not know why though. I know for a fact the program crashes AS SOON AS THE workbookname.open command is run. It does not even try to enter the rest of the code.

    Leon

  • Re: Excel crashes when opening multiple documents


    This may be very hard for us to diagnose, given the nature of the problem. If there are more class methods then you really need to upload all of them. Don't worry about the adverts they are always on the first and last posts of a page.

    One thing I did notice is that in functions: PreHeating, CW and HW you are declaring Cell as a Range but not setting it to Nothing at the end. Technically Cell is an object so this is probably a small memory leak. If you have anything similar but inside a loop then this may be the problem. If you want to be 100% safe then every declared variable should be set to Nothing before leaving a function/procedure.

    Something else to try is to set the VBE to break on all errors: Tools > Options > General > Error Trapping. That may enable you to catch an error in the class module that is causing a problem but not being highlighted until it has killed Excel.

  • Re: Excel crashes when opening multiple documents


    In the insertData sub I set the ranges equal to nothing. Maybe its best to ignore the update_click sub, since I only updated my code in the button for debuggin purposes.

    That is all the code I have on this workbook. The problem has to be there somewhere. Thank you for all the help Rob.

    Regards,
    Leon

  • Re: Excel crashes when opening multiple documents


    Hey Rob,

    Thanks again for your time. I did as you suggested. The code did not break anywhere.

    What I did do though, is to put a break on the line

    Code
    Workbooks.Open ThisWorkbook.Path & "\" & Workbooks(workbookname).Worksheets("Sheet1").Cells(i, 1).Value

    and when i press "F8" (the 6th time) it doesnt move to the next line, it just CRASHES.

    Mind boggling stuff...

    Regards,
    Leon

  • Re: Excel crashes when opening multiple documents


    It might be worth noting that, the design documents where the summary workbook gets its information from, is quite large with several complex calculations each. I do not have a problem opening each individual document though. Its just that if I have a few open at the same time, my computer becomes extremely slow.

    Leon

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!