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

Hello,  I am using vb.net 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?  
TheUndeciderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omegaomegaDeveloperCommented:
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:

http://www.tushar-mehta.com/excel/vba/xl_doesnt_quit/
http://support.microsoft.com/kb/178510/

Cheers,
Randy
0
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
 
Try
    're-initialize excel app
    ExlApp = New Excel.Application
 
    If ExlApp Is Nothing Then
        ' throw an exception
        Throw (New Exception("Unable to Start Microsoft Excel"))
    Else
        'supresses overwrite warnings
        ExlApp.DisplayAlerts = False
        'check if file exists
        If File.Exists(FilePath) Then
            aBook = ExlApp.Workbooks.Open(FilePath)
        Else
            aBook = ExlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
        End If
        With ExlApp
            .SheetsInNewWorkbook = 1
            '.Workbooks.Add()
            .Worksheets(1).Select()
            '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
            Next
            '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)
                Next
            Next
 
            'Check if the file exists
            If File.Exists(FilePath) Then
                ' It does. Save it 
                .ActiveWorkbook().Save()
            Else
                'Save it with the given file name
                .ActiveWorkbook().SaveAs(Filename:=FilePath)
            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)
 
Finally
    ' Make sure that Excel is properly exited and al the COM objects are released
    aBook.Close(false)
    ExlApp.Quit()
    System.Runtime.InteropServices.Marshal.ReleaseComObject(ExlApp)
    aBook = Nothing
    ExlApp = Nothing
 
    GC.Collect()
    GC.WaitForPendingFinalizers()
 
    GC.Collect()
    GC.WaitForPendingFinalizers()
 
End Try

Open in new window

0
omegaomegaDeveloperCommented:
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?

Cheers,
Randy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.