+ Reply to Thread
Results 1 to 12 of 12

Macro works but crashes Excel 2010

  1. #1
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Question Macro works but crashes Excel 2010

    This set of macros does everything they're supposed to do: stop the user from saving if they haven't entered the basic info in a few cells, create a folder and save the file there under a name from a cell, run spellcheck, and timestamp the footer with the user and time saved.

    The only problem is that it crashes Excel every time it's used and Excel has to run auto-recover to reopen the file. Can anyone please help me figure out what I'm doing wrong?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro works but crashes Excel 2010

    I would suggest that you put a Debug.Print between each line of code and display the pieces of data that are being used. That way, you'll know how far it gets and have some information to look at.

    Sorry I can't be more specific.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    It always crashes creating the new folder, then it's usually alright but sometimes it saves the file twice in a row on resaving; first I get the message "...do you want to overwrite the file?" and when I select "yes", the save as dialogue pops up.
    Last edited by Willardio; 10-07-2012 at 08:18 PM.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro works but crashes Excel 2010

    TMShucks has provided the correct answer.
    Last edited by Trebor76; 10-07-2012 at 08:27 PM.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro works but crashes Excel 2010

    You're in the Before_Save event and you're saving the workbook. You need to disable events before trying to save and then re-enable afterwards.

    Regards, TMS

  6. #6
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    thanks for the suggestion trebor. Same error, still crashes. but it does only save one way on the re-save, so that's an improvement.

  7. #7
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    Thank you TMShucks, I have a macro for that, still getting the same error.

  8. #8
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    this is the macro I use to save without running the event, I got it in another thread:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    did i "Dim" something wrong?

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro works but crashes Excel 2010

    Maybe you should post a sample workbook. We're working a bit in the dark here.

  11. #11
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    Here's the sample (second try)
    Sorry, there was nothing in the cell to "save as" in that previous file, but this one is right:

    save event sample 2.xlsm

    And thanks again for taking a look.

    -Willardio
    Last edited by Willardio; 10-07-2012 at 09:59 PM.

  12. #12
    Forum Contributor
    Join Date
    09-19-2012
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: Macro works but crashes Excel 2010

    putting a save event in a beforesave_event creates an infinite loop that's guaranteed to crash the program, unless you disable events in a line prior to the save event, then re-enable events in the line after, in which case it saves twice.

    The code below accomplishes the important part of what I set out to do, which is run spellcheck on a protected sheet and prevent users from leaving certain cells blank before saving. I will try to figure out how to use getSaveasName to extract the save name from a cell, but for now this is good enough. The accompanying BeforeClose event is necessary to keep the program from freezing at close. Application.Events will re-enable automatically next time you open the file.

    Please Login or Register  to view this content.
    Last edited by Willardio; 10-10-2012 at 12:14 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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