Results 1 to 11 of 11

Thread: kill excel instance

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    kill excel instance

    dfsdttfhgj
    Last edited by v_gyku; Sep 19th, 2005 at 04:04 AM.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: kill excel instance

    You need to explicitly 'Close' the instance of Excel. All you have done (in your example) is destroyed the Object you created


    So try: objExcel.Close

    then destroy objExcel

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: kill excel instance

    You need to set the sheet to nothing, close the workbook, set the workbook to nothing, quit the application, and then set the application to nothing.
    In that order:

    VB Code:
    1. Set ExlSheet = Nothing
    2.   ExlWorkBook.Close SaveChanges:=False
    3.   Set ExlWorkBook = Nothing
    4.   ExlAppTemp.Quit
    5.   Set ExlAppTemp = Nothing
    6.   Exit Sub

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: kill excel instance

    You are only setting the Excel Object to nothing if you close it there.
    You should set it to nothing regardless. Put the duplicated code after the if statemnt. It won't hurt to set it to nothing twice.

    Follow the steps above with everything.

    Here is a module I use to close my apps.


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  Dim frm As Form
    5.   Dim obj As Object
    6.   For Each frm In Forms
    7.      If frm.Name <> Me.Name Then ' Unload this form LAST
    8.        For Each obj In frm
    9.          On Error Resume Next
    10.            Unload obj
    11.            Set obj = Nothing
    12.        Next
    13.        Unload frm
    14.        Set frm = Nothing
    15.      End If
    16.     Next
    17.     On Error Resume Next
    18.       For Each obj In frm
    19.         Unload obj
    20.         Set obj = Nothing
    21.       Next
    22.       Set frm = Nothing
    23.       Unload Me
    24. End Sub

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: kill excel instance

    There may be a problem with your IsAppOpen function. Do you really need to use this? Can you post the code for it?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: kill excel instance

    Quote Originally Posted by dglienna
    You are only setting the Excel Object to nothing if you close it there.
    You should set it to nothing regardless. Put the duplicated code after the if statemnt. It won't hurt to set it to nothing twice.

    Follow the steps above with everything.

    Here is a module I use to close my apps.


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  Dim frm As Form
    5.   Dim obj As Object
    6.   For Each frm In Forms
    7.      If frm.Name <> Me.Name Then ' Unload this form LAST
    8.        For Each obj In frm
    9.          On Error Resume Next
    10.            Unload obj
    11.            Set obj = Nothing
    12.        Next
    13.        Unload frm
    14.        Set frm = Nothing
    15.      End If
    16.     Next
    17.     On Error Resume Next
    18.       For Each obj In frm
    19.         Unload obj
    20.         Set obj = Nothing
    21.       Next
    22.       Set frm = Nothing
    23.       Unload Me
    24. End Sub
    This will not work with Excel objects as it is more used for VB variable objects.

    Without seeing all your Excel code we can not determine what your leaving open. You MUST close and destroy all Excel objects and quit and destroy the application(s) object(s) in order to release all references to Excel and allow it to close.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: kill excel instance

    I have never had a problem qoing a myExcel.Quit function then setting all my excel objects to nothing. The program closes just fine and I think I am getting all of my resources back. Am I wrong? I know that Excel closes when I do this without issue.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: kill excel instance

    It may close fine and not show in the taskmanager but I do believe that the references would still be resident and not relase all your resources.

    Edit: Moved to Office Development Forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: kill excel instance

    To close without saving....

    myExcel.DisplayAlerts = False
    myExcel.Quit

    then set objects = Nothing
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: kill excel instance

    Instead of .DisplayAlerts you could do the same thing with setting the .Saved property of the workbook to True in order to bypass the prompt.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: kill excel instance

    Hey guys ! I am not getting the solution.

    I need ur help guys!



    I am trying this :

    I have also tried many other things:

    Once i write the following code i think excel should go from the taskbar..

    is there any thing which i might have done because of which it might not be going?



    Code:
    ObjExcel.Quit
    Set ObjExcel = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width