Jump to content

Excel Instance Hung in Background of VBNET Application


Recommended Posts

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...