bjhuffin Posted August 3, 2009 Posted August 3, 2009 Is there a way to ensure an Excel object in the VB-NET code gets released when finished? The problem I seem to have is that my application runs via a modal form through the netload command. The application does it's extraction and processing of data, then spits the info out into an Excel spreadsheet. What I've noticed is that since the application is running within the AutoCAD namespace and since it is this application that initializes the Excel application... Excel doesn't actually close until after my application is closed. For safe measure, I want to ensure the Excel object is totally closed out even before my application closes. Otherwise, an error downstream can cause the Excel object to continue to run in the background. Actually, the Excel instance hangs around in the background until the AutoCAD session closes. Not cool... Does anyone have any ideas? Here is my initializing and closeout code: Imports Microsoft.Office.Interop ... 'Declare Excel Objects Dim objExcel As New Excel.Application Dim objExcelWB As Excel.Workbook = Nothing Dim objExcelWS As New Excel.Worksheet Try 'Initialize the Workbook objExcelWB = objExcel.Workbooks.Add With objExcelWB .... Workbook Code With objExcelWS ... Worksheet-Specific code End With End With Catch exClose As Exception ... Error Handling Finally 'Exit Excel and Clean-up resources objExcel.Application.Quit() 'or this... I've tried both objExcel.Quit() objExcelWS = Nothing objExcelWB = Nothing objExcel = Nothing End Try Any help would be appreciated. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.