How to close Excel 2003 object through ASP.NET?

Posted on 2005-05-05
Last Modified: 2010-04-07
Hi Friends,

I am using the following piece of code to write an Excel file through ASP.NET and VB.NET.

            Dim objxlsAppln as Object
            Dim objxlsWorkSheet as Object
            objxlsAppln = CreateObject("Excel.Application")
            objxlsWorkSheet = objxlsAppln.ActiveWorkbook.ActiveSheet
            .(Code to writing Excel File)
            'Code to save file and close excel object
            objxlsWorkSheet = Nothing
            objxlsAppln = Nothing

My problem is even after the above code is executed the excel.exe process is not closed. This runs well in Excel prior to version 2003, but in Excel 2003 it is not closing the excel.exe process.

Please help.

Question by:nitinkpr
    LVL 12

    Expert Comment

    Hi nitinkpr,
      I looked at the help briefly
    the only thing I came up with is to try the application.DisplayAlerts = false statement before you call application.quit -
    Maybe something is coming up that you're not seeing?
    My hunch is that it works fine with 2003 - and that there's something specific to your install thats causing it.
    - Jack

    Author Comment

    Hi fruhj,
    i tried the the suggestion that u had given, but still problem remains the same.

    LVL 12

    Expert Comment

    When you run this code, does excel come up on the screen?

    (I can't remember the default behaviour, I think it's hidden)

    There's should be an application.visible property you can set to true.

    If you haven't already, try doing that right after you do your create object("excel.application") so you can watch excel through the process - maybe you'll find something.
    LVL 11

    Expert Comment

    I use this and it works without problem....

    Dim oXL As Excel.Application
    oXL = CreateObject("Excel.Application")

    'Close & Quit
    oXL = Nothing

    Try declaring it as an excel app instead of an object. If that doesnt work then it might be your excel version - can you let us know which version it is please.



    Author Comment

    Thanx for ur replies.

    I have declared as an Object because I want to use late binding without including Excel in project references and without using its interop version.

    I am using Excel 2003 and the code snippet that I have given above runs well with version 2002 and prior.

    LVL 26

    Expert Comment

    i have read and seen this problem and most of time .. no definite solution is found .. u can search the net and u will see lots of unanswered threads on the same issue .. anyway, u would try this
    set all the objects to nothing in the following order (based on which u have used)
    range, worsheet, workbooks, excel application .. also remeber to use the ReleaseComObject (the way u have done it) for all these objects .. except the range .. again in the same order .. i had read somewhere that this problem also arises when one of the objects used is not released ... give this a try ..
    LVL 26

    Accepted Solution

    I forgot to mention . .close all the workbooks before releasing the memory ..

    have a look at these links .. seems some of them were able to solve the problem

    here the solution says about not using "with .. end with" statement ..

    here the solution says about using a loop to release the objects

    again a loop ... last comment by Tad and lecky
    LVL 26

    Expert Comment

    I think I have covered all the options in the links provided ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now