+ Reply to Thread
Results 1 to 4 of 4

Excel crashes when trying to save one particular xlsm only after running macro

  1. #1
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Excel crashes when trying to save one particular xlsm only after running macro

    Hi all,

    I've been experiencing this one problem with a file which pulls worksheets in from another file via macro, here's the weird thing:

    If I open the file and make some modifications then save it, it's fine.
    If I open the file and run a particular macro, then try and save, it crashes (Excel is not responding, closing program etc.)

    It crashes whatever kind of saving I try to do. Save As, Autorecover etc...

    The macro basically takes an external workbook and copies a particular sheet from the external workbook to this workbook.

    Does Excel have some strange constraint when it comes to adding/deleting worksheets via VBA?

    Here's the snippet of code that seems to be causing the problem:
    c.Offset(0,1) is the path to the external workbook
    c.Offset(0,2) is the worksheet name it should pull
    c.Offset(0,3) is the new name it should assign the copied worksheet in the current workbook.

    Please Login or Register  to view this content.
    Thanks and regards
    Duncan

  2. #2
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Excel crashes when trying to save one particular xlsm only after running macro

    Well, I have been having certain moments experienced when my excel file used to get stuck up with no response from the application for minutes and sometimes hours - with no more options I used to KILL the process using task manager.

    As per my experience, there are many obvious reasons which can effect the performance of a macro. Below are the listings:

    1. Calculations : We know that - after making any changes to any cell in the sheet, if there are other cells dependant on the changed cell - those dependant cells would reflect the changes - due to Application.Calculation setting set to Automatic.

    2. Triggering of Events due to Changes : Macros tend to make changes in the cells, so if there are events defined to get triggered when changes happen, they get fired along with each changes that are made to the sheets. Very likely, we do define certain events like Worksheet_Change(), so those events get triggered everytime the values in any cell in the sheet is changed.

    3. Screen Updates : Well, some macros do involve opening / closing / switching files / sheets - these kind of updates when done by processor while running macro is just too fast that even the outputs that are sent over to the display unit gets the images piled up and sometimes stops responding. This again, does take good amount of display memory and CPU usage.

    4. Alerts Thrown by Application (Optional, not actually slows down but prompts for annoying actions): Macro sometimes performs tasks that requires user interventions like merging of cells. Though it doesn't create a harm in saying "yes! let's do this", but what if we have to do this for a hundred cells, where I just want columns A should merge with B for next 100 rows? You'll have to say, "Yes!" for next 100 times.

    So you can boost up your macro speed if you set a control over these things. If you know when to perform what.. you can easily direct the flow and speed of your macro. Each of these feature has its own importance. Its just that one should know what to do and when to do.

    here's a piece of code to Boostup your macro speed (My personal favorite method which I incorporate in every reporting tool of mine). Do make sure when to Enable / Disable them.

    Please Login or Register  to view this content.
    Add this method and call it as
    BoostMacroPerformance True
    in the beginning of your code and when about to end
    BoostMacroPerformance False
    Do Make use of :
    1. Application.Calculate() : When you want the sheet to calculate each cell before performing any task, and
    2. Application.EnableEvents = True / False : Whenever you need the sheet to raise / avoid an event if you've defined them to run when values are changed.

    if none of the above things work out for you.. then you need to go through the logic of your codes. And must avoid lot of calculations in the sheet. Especially like, SUMPRODUCT, COUNTIFS, COUNTIF, SUMIF, SUMIFS and other conditional type functions. Better use functions through macros for if there are thousands of cells performing just those heavy calculations and if only values in the cell can satisfy your needs.

    I believe using the above tips efficiently, you will be able to cater your issues with Not-Responding thing. After I have started implementing these into my reports and works, I have observed "ZERO" crashing of Excel application till date - even if I have a hundred thousands of cells filled, and my macros run at good speed too.
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  3. #3
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Excel crashes when trying to save one particular xlsm only after running macro

    Another possible reason can be that you have that file open which the macro is trying to open..

  4. #4
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Excel crashes when trying to save one particular xlsm only after running macro

    Quote Originally Posted by codeslizer View Post
    Another possible reason can be that you have that file open which the macro is trying to open..
    If this was the case then Excel would crash while the macro is running.

    The macro runs fine, and updates all the sheets/cells. Excel only crashes when I try to save the updated workbook.

+ 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] Excel Crashes when trying to save after running a sort macro
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2013, 09:23 AM
  2. [SOLVED] Save XLSM without running, but retaining macros
    By adkaraczun in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2012, 07:05 AM
  3. After saving the spreadsheet and then running the macro, Excel crashes
    By hydronicengr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2012, 08:03 PM
  4. Excel Crashes when saving after running macro
    By msmithdynamicsgp in forum Excel General
    Replies: 0
    Last Post: 10-24-2011, 12:16 PM
  5. Excel crashes after running Macro
    By sjl17 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-25-2005, 06:27 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