+ Reply to Thread
Results 1 to 6 of 6

Closing Excel from a DLL

  1. #1
    CraigB
    Guest

    Closing Excel from a DLL

    I've written a VB6 dll that creates an instance of the
    Excel.Application object, however I can't seem to close the process
    once I've finished with it.

    Although I call Quit() and set my object variable to Nothing I can
    still see the Excel.exe process running in Task Manager.

    Is there someway I can force this process to end?

    Thanks in advance

    Craig

  2. #2
    Bob Phillips
    Guest

    Re: Closing Excel from a DLL

    Craig,

    Have you made sure that all workbooks are closed before quitting?

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "CraigB" <[email protected]> wrote in message
    news:[email protected]...
    > I've written a VB6 dll that creates an instance of the
    > Excel.Application object, however I can't seem to close the process
    > once I've finished with it.
    >
    > Although I call Quit() and set my object variable to Nothing I can
    > still see the Excel.exe process running in Task Manager.
    >
    > Is there someway I can force this process to end?
    >
    > Thanks in advance
    >
    > Craig




  3. #3

    Re: Closing Excel from a DLL

    The Count property on the WorkBooks collection is 0 just before I call
    Quit and I explicitly close my workbook before calling quit.
    btw I'm using Office 2003.

    Craig


  4. #4
    Bob Phillips
    Guest

    Re: Closing Excel from a DLL

    Craig,

    Another thought is that you should maybe try releasing all the object
    variables after the quit (you know, Set xlApp = Nothing etc.). Try all of
    them.

    If this fails, try this hint posted by Jake Marx a while back

    ....
    However, when automating Excel (and when Excel is not visible), problematic
    code will run, and you may not be notified of an error that has occurred.
    When this happens, the .Quit and Set = Nothing commands seem to release the
    reference VB has to Excel, but the Excel application stays open in a limbo
    state. The best way to debug this type of situation is to set the Visible
    property of the Excel.Application object to True at the beginning of your
    code and step through it. Any runtime errors should be raised in the Debug
    environment when you do it this way. Once you get the code working
    correctly, then you can get rid of the Visible statement.
    ,,,

    If this is not the problem, try reducing your code to the bare bones that
    fails to work, post it, and I will try to re-create.


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    <[email protected]> wrote in message
    news:[email protected]...
    > The Count property on the WorkBooks collection is 0 just before I call
    > Quit and I explicitly close my workbook before calling quit.
    > btw I'm using Office 2003.
    >
    > Craig
    >




  5. #5

    Re: Closing Excel from a DLL

    Bob,

    I thought it might have been my object variable too as I get references
    to sheets and the workbook but explicitly setting them to Nothing first
    didn't help.
    I've been playing with it a bit more and seem to have it narrowed down
    to something to do with the SaveAs method.

    Dim xls As Excel.Application
    If xls Is Nothing Then Set xls = CreateObject("Excel.Application")
    'xls.DisplayAlerts = False

    Dim wkbk As Workbook, sheet As Worksheet
    Set wkbk = xls.Workbooks.Add
    Set sheet = wkbk.ActiveSheet

    wkbk.SaveAs "c:\temp.xls"
    wkbk.Close SaveChanges:=False

    Set sheet = Nothing
    Set wkbk = Nothing

    xls.Quit
    Set xls = Nothing

    If I comment out the SaveAs line then the Excel process does end but
    with it in, it hangs around.

    Cheers

    Craig


  6. #6
    Rex
    Guest

    Re: Closing Excel from a DLL

    Maybe this has something to do with touching the file system. I have an
    equally simple example which also leaves Excel running:
    Dim XL As Excel.Application
    Dim WB As Excel.Workbook
    Set XL = CreateObject("Excel.Application")
    XL.Visible = True
    Set WB = XL.Workbooks.Open("C:\temp\Anyold.xls")
    WB.Close False
    Set WB = Nothing
    XL.Quit
    Set XL = Nothing

    I can "fix" it by taking out the .Open and .Close. I posted this in
    November and the only suggestion was to go back and kill off the Excel
    processes when I was done with them.

    "[email protected]" wrote:

    > Bob,
    >
    > I thought it might have been my object variable too as I get references
    > to sheets and the workbook but explicitly setting them to Nothing first
    > didn't help.
    > I've been playing with it a bit more and seem to have it narrowed down
    > to something to do with the SaveAs method.
    >
    > Dim xls As Excel.Application
    > If xls Is Nothing Then Set xls = CreateObject("Excel.Application")
    > 'xls.DisplayAlerts = False
    >
    > Dim wkbk As Workbook, sheet As Worksheet
    > Set wkbk = xls.Workbooks.Add
    > Set sheet = wkbk.ActiveSheet
    >
    > wkbk.SaveAs "c:\temp.xls"
    > wkbk.Close SaveChanges:=False
    >
    > Set sheet = Nothing
    > Set wkbk = Nothing
    >
    > xls.Quit
    > Set xls = Nothing
    >
    > If I comment out the SaveAs line then the Excel process does end but
    > with it in, it hangs around.
    >
    > Cheers
    >
    > Craig
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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