CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2001
    Posts
    7

    excel won't quit

    I am accessing an excel spread sheet via a vb command button. I update one or more of the fields and then when data exchange is complete using the following function: to close excel
    Problem is that Excel still stays active. I checked by doing an Ctl+Alt+Del and it is still in the tasks window. What am I forgetting to close.

    [vbcode]
    Function Close_applications()
    xlApp.AlertBeforeOverwriting = False
    xlApp.ActiveWorkbook.Save
    'close app here
    xlApp.ActiveWorkbook.Close
    Clipboard.Clear
    EMPLOYEEFOUND = False
    xlApp.Quit
    Set xlApp = Nothing
    End Function
    [\vbcode]


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: excel won't quit

    xlapp.Workbooks.Close
    will close all workbooks and not only the one active (you sure you have only one?)
    Set xlapp = Nothing 'after here excell should disappear from tasks if all references have been released.



    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Aug 2001
    Posts
    7

    Re: excel won't quit

    I tried xlApp.Workbooks.Close
    like you suggested still no luck. I'm wondering whether excel is the problem. even when I press end task it may take 5 or 6 seconds before i'm asked to confirm. And Yes I only have 1 sheet in my workbook. thanks for the suggestion anyway..any one else have any solutions.


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: excel won't quit

    If you are performing long tasks (ie: do while...loop) or if you've imported lots of data, it may be. However, ther's a chance you referenced some other object of excell and did not close/release them. have a look at your code for "set something = somethingElse" (and optionally: "something.open") and a lack of a correspondent (optionally: "something.close" and) "set something = nothing".
    Hope this helps

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    May 2001
    Posts
    46

    Re: excel won't quit


    'after the sentence

    xlApp.ActiveWorkbook.Close

    'you have to put
    xlApp.Quit ' this will close excel
    set xlApp = 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

Featured