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

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?  
Who is Participating?
omegaomegaConnect With a Mentor DeveloperCommented:
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?

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:

TheUndeciderAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.