+ Reply to Thread
Results 1 to 15 of 15

vba excel - close Excel instance from modal form keeps window open

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    vba excel - close Excel instance from modal form keeps window open

    Below is code to shut down (quit the excel instance) my project. There are two exit buttons to which the user can exit the project. One is within a form (modal) on a login screen. The other exit button is within a different form (modeless) within the project after login is achieved. The exit code from the modeless form closes the instance completely. Attempting to exit from the modal form closes the form, but the excel window remains open. The desire is for the excel instance to shut down completely. When I change the modal form to modeless, the excel instance shuts down properly. Why is this? What do I need to add to completely shut down the excel instance from a modal form using the below code?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: vba excel - close Excel instance from modal form keeps window open

    Hiya, try unloading the form before workbook.close or application.quit?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    Hello Poizhan,
    thanks for the suggestion, but I already tried that. I also tried Hiding the form before the close or quit. That does not work either.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba excel - close Excel instance from modal form keeps window open

    May be try something like...

    Assuming you want to save workbook at exit. If not, change True to False.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    Thanks CK. A couple aspects to this.

    If count>1 then project closes and Excel window for the workbook closes.

    If count<1 then project closes but Excel window stays open.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: vba excel - close Excel instance from modal form keeps window open

    Do you have any add-ins loaded or a personal macro workbook?
    Rory

  7. #7
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    .....nope.

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: vba excel - close Excel instance from modal form keeps window open

    I suggest you rework your code so that the code that loads the form also takes care of unloading it and either closing the workbook or quitting the application. The user form really shouldn't do that itself.

  9. #9
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    I understand that it's discouraged to have the user form close or quit the application for many reasons. I've read a little about it through various posts, but have difficulty grasping implementation if entire ui is form driven.

    Currently code that loads the form is executed on a Workbook_Open event and user cannot close the Excel document using Excel functions.

    I thought by having the command call a module subroutine since that executes properly when forms are modeless.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: vba excel - close Excel instance from modal form keeps window open

    Firstly, I would not recommend calling code to load a userform directly in the Open event, especially if you intend to close the workbook and/or application when the form is done. Instead use Application.OnTime to call a routine in a normal module to load the form once the workbook is properly loaded. That routine can also take care of the cleanup when the form is unloaded.

  11. #11
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    Currently on the open event there is a timer sub. The sub is within ThisWorkbook. Should the timer sub be within a standard module then?
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: vba excel - close Excel instance from modal form keeps window open

    No, I mean that the frmSplash.Show line needs to be in a routine in a normal module that you call using Application.OnTime. Even if it's just:

    Please Login or Register  to view this content.
    and:

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    Forms unload and the clean up completes, but the excel instance still remains open.

  14. #14
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: vba excel - close Excel instance from modal form keeps window open

    Hmm, just tested code from post #4. Worked fine in my environment with multiple workbook or single workbook open.

    There must be something in your project that's preventing Excel instance from closing completely. I'd suggest, commenting out sections etc, to pinpoint what exactly is interfering with Excel instance being closed. Then first terminate that process before attempting to close Excel instance.

  15. #15
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel - close Excel instance from modal form keeps window open

    idk. I've tried all the options including your suggestion CK76 and Excel still will not quit. I commented the If Then statement leaving just Application.Quit and the workbook window still remains open.

    It seems fairly straight forward to me. I've stripped all the code down and even tried some snippets into the BeforeClose event. A MsgBox "test" fires, but ThisWorkbook.Close False OR Application.Quit still does not close the instance window.

    I guess as long as the workbook cleans up and closes I may have to just live with this. Just strange that the window instance completely closes when other Excel files are open, but doesn't when it's the only file open.

+ 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. Replies: 1
    Last Post: 03-23-2018, 03:52 PM
  2. Open new instance of excel window if an excel window already open
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-07-2015, 10:04 PM
  3. Non modal form closes with modal form when it is closed
    By ryan.wherry in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2015, 12:45 PM
  4. excel 2013 vba - show modal userform - can't open another .xls file
    By excel_joe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2014, 01:37 PM
  5. Must close or hide topmost modal form first
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2011, 01:41 PM
  6. [SOLVED] Can a non-modal form be viewed w/o Excel in the background?
    By cjmd in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2006, 01:35 PM
  7. Replies: 1
    Last Post: 02-21-2005, 01:06 PM

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