Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't close automation reference to Excel
Message
 
To
All
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Title:
Can't close automation reference to Excel
Miscellaneous
Thread ID:
00227106
Message ID:
00227106
Views:
43
I am using automation to open a text file in Excel. My intent is to have Excel open the file, do some formatting and then show the result to the user. At that point I want to release my references to Excel so that the user can do what he wants with the file. However, I find that if I close Excel while my application is still running that I still (apparently) have a reference to Excel that prevents it from shutting down completely. (Although the application does disappear from the screen, the task manager reveals that it is still running.)

The code below shows whats happening...

....
Dim oExcel As Excel.Application
Dim oWorkSheet As Excel.Worksheet
Dim oWorkBook As Excel.Workbook
Dim sFileName As String

Set oExcel = Excel.Application

'open the temp file... activate the sheet....
oExcel.Workbooks.Open sFileName, , , 1 'tab delimited

oExcel.Workbooks(FileOf(sFileName)).Activate
Set oWorkBook = oExcel.ActiveWorkbook
Set oWorkSheet = oExcel.Worksheets(FileOf(sFileName, False))

oWorkSheet.Columns.AutoFit
oExcel.Goto oWorkSheet.Range("A1")
oExcel.Visible = True
Set oWorkSheet = Nothing
Set oWorkBook = Nothing
Set oExcel = Nothing

SendListViewToExcel_Exit:
Exit Sub

End Sub

Any suggestions?
Next
Reply
Map
View

Click here to load this message in the networking platform