Application.Quit produces Run-Time Error 1004

  • Application.Quit is producing Run-Time Error 1004. I use a workbook with a macro to generate a second workbook, then save the second workbook and close it. After that I'm trying to use Application.Quit to close the workbook that has the macro in it. When I run the macro from start, I get the Run-Time error at the Application.Quit line of code. When I select "Debug" Application.Quit works, without showing anything.


    NOTE: When I use F8 to step through the code, everything works fine; no Run-Time error.

  • Make sure all object or range references have been set = nothing before you ".quit".
    Make sure .displayalerts and .screenupdating and .calculation are switched back "on/automatic" before .quit.
    Make sure there is no other application trying to reference Excel...

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Start commenting out items and see where you get the error. Are there other workbooks open? Like personal or something else. Might be an event in them throwing an error. What happens when you mash the "X" button in the upper right?

  • I've tried the above recommendations with no help (Thank you).


    At the time of the Application.Quit only this workbook with the macro is open. The following code is the last few lines.



    I use the asterisks to line my code problems, makes them easier to find later.

  • I have fixed my problem...Thank you both for your help and information.


    Here's how I fixed it...if you're interested:

    Code
    Application.DisplayAlerts = True     'stops suppressing prompts and alerts while code is running.
        Application.Workbooks(2).Close SaveChanges:=False     'closes generated file.
        Application.Quit     'Quits Excel.
        Application.ActiveWindow.Close SaveChanges:=False     'closes the active window...required for quit.
        ActiveWorkbook.Close SaveChanges:=False     'closes the active workbook...required for quit.

Participate now!

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