|
-
Apr 20th, 2004, 09:48 AM
#1
Thread Starter
New Member
Automation instance termination
I am automating Excel 2000 from and ASP.Net web application. I used the DCOM configuration tool to allow the proper users to create instances of Excel, but I can't get the Excel objects to be released from memory. After the application terminates, the Excel instances are still in memory. Here is some code showing how I create the objects and how I am cleaning up after them:
'Create excel objects
Dim oXL As Excel.Application
Dim oBook As Excel._Workbook
Dim oSheet As Excel._Worksheet
Dim oMacro As VBIDE.VBComponent
'Create empty value
Dim oMissing As Object = System.Reflection.Missing.Value
'Create new workbook
oBook = oXL.Workbooks.Add()
'Add code, do stuff, blah, blah, blah...
'Add macro data (Workbook = 1, Sheet1 = 2 Sheet2 = 3...)
oMacro = oBook.VBProject.VBComponents.Item(1)
'Workbook_Open routine to prompt user of partial chart status
strCode = "Private Sub Workbook_Open()" & vbCrLf
strCode = strCode & vbTab & "ThisWorkbook.Worksheets(1).IsPartial("
If Session("previous") = Nothing Then
strCode = strCode & "False)" & vbCrLf
Else
strCode = strCode & "True)" & vbCrLf
End If
strCode = strCode & "End Sub"
'Add the code to the project
oMacro.CodeModule.AddFromString(strCode)
'DO MORE STUFF......
'Cleanup (I don't think that it works)
If Not oBook Is Nothing Then
oBook.Close(False, oMissing, oMissing)
End If
If Not oSheet Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet)
oSheet = Nothing
End If
If Not oBook Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
End If
If Not oMacro Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oMacro)
oMacro = Nothing
End If
If Not oXL Is Nothing Then
oXL.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL)
oXL = Nothing
End If
GC.Collect()
I'm not really sure where the problem is. I'm not getting any errors or exceptions. Are there any gurus out there that can help me?
Thanks in advance,
Maynard
-
Apr 21st, 2004, 08:39 AM
#2
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|