Kill Excel process in Visual Studio 2003 (Excel 2000 and VB.NET 2003)

Posted on 2008-11-17
Last Modified: 2013-11-26
Hello,  I am using 2003 and Office 2000.  I am trying to find a way to use an Excel spreadsheet in .NET, but I still have an instance of Excel running in task manager.  

I'm trying to find a way to find the ID process for the excel spreadsheet I am using and then kill it.  

Is there a way to get the process ID for Excel 2000 and then kill it without killing any other opened Excel applications?  
Question by:TheUndecider
    LVL 12

    Expert Comment

    Hello, TheUndecider,

    I wonder if your problem is actually due to an unqualified reference to an Excel object.  See the following links for more information:


    Author Comment

    Well... I had pasted my code in another question, but I still have problems.  Here's my code again so you can see whether I do have an unqualified reference to an Excel object.
    Dim ExlApp As Excel.Application
    Dim iCol, iRow, iColVal As Integer
    Dim bNew As Boolean
    Dim i As Integer
    FilePath = "c:\MyExcelFile.xls"
    ' Open the document that was chosen by the dialog
    Dim aBook As Excel.Workbook
        're-initialize excel app
        ExlApp = New Excel.Application
        If ExlApp Is Nothing Then
            ' throw an exception
            Throw (New Exception("Unable to Start Microsoft Excel"))
            'supresses overwrite warnings
            ExlApp.DisplayAlerts = False
            'check if file exists
            If File.Exists(FilePath) Then
                aBook = ExlApp.Workbooks.Open(FilePath)
                aBook = ExlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
            End If
            With ExlApp
                .SheetsInNewWorkbook = 1
                'For displaying the column name in the the excel file.
                For iCol = 0 To ExportDataSet.Tables(0).Columns.Count - 1
                    ''clear column name before setting a new value
                    .Cells(1, iCol + 1).Value = ""
                    .Cells(1, iCol + 1).Value = ExportDataSet.Tables(0).Columns(iCol).ColumnName.ToString
                'For displaying the column value row-by-row in the the excel file.
                For iRow = 0 To ExportDataSet.Tables(0).Rows.Count - 1
                    For iColVal = 0 To ExportDataSet.Tables(0).Columns.Count - 1
    .Cells(iRow + 2, iColVal + 1).Value = Trim(ExportDataSet.Tables(0).Rows(iRow).ItemArray(iColVal).ToString)
                'Check if the file exists
                If File.Exists(FilePath) Then
                    ' It does. Save it 
                    'Save it with the given file name
                End If
            End With
            'Let the user know that the excel file was exported successfully
            MsgBox(FilePath & " File exported as Excel spreadsheet sucessfully")
     	  'clear the file path
    	  FilePath = Nothing 
        End If
        'warn users if there's an error
    Catch ex As Runtime.InteropServices.COMException
        MsgBox("ERROR: " & ex.Message)
    Catch ex As Exception
        MsgBox("ERROR: " & ex.Message)
        ' Make sure that Excel is properly exited and al the COM objects are released
        aBook = Nothing
        ExlApp = Nothing
    End Try

    Open in new window

    LVL 12

    Accepted Solution

    Hello, TheUndecider,

    I couldn't see anything in your posted code that would cause the "unqualified reference" problem mentioned.  So (after substituting simple values for the ExportDataSet object) I tried running it.  

    In my case it didn't have any trouble at all closing/quiting Excel.  Perhaps the problem lies in some other piece of code called before or after this routine.  Or could it be in ExportDataSet?  If you run just the code posted (replacing ExportDataSet with appropriate constants) do you still have the problem?


    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

    Join & Write a Comment

    Suggested Solutions

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    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…

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now