Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can't close automation reference to Excel
Message
 
À
07/06/1999 14:51:33
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00227106
Message ID:
00227428
Vues:
19
>>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


This causes Excel to shutdown, however. I want the user to be able to continue to have Excel open. (Your solution does solve the reference problem, however.)

Stan B
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform