Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't close automation reference to Excel
Message
From
07/06/1999 14:51:33
 
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00227106
Message ID:
00227158
Views:
24
>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?



Try this before setting oExcel = nothing:
oExcel.Quit
Guy Barrette, MCSD
============
Blog http://weblogs.asp.net/guybarrette
Microsoft Regional Director, Montreal, Canada www.microsoft.com/rd
MVP, ASP.NET http://mvp.support.microsoft.com/
President, Montreal Visual Studio User Group www.guvsm.net
INETA Regional Rep for Quebec www.ineta.org
UniversalThread Magazine Columnist (.NET Books Review Column) www.utmag.com
Tech Chair French Track, DevTeach 2004 & 2005 www.devteach.com
Business Architect, Microsoft Team - Nurun Inc www.nurun.com
XBox Live Gamer Tag: Slomo QC CA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform