Excel Object Not releasing from Task Manager (Vb.net)

D

Dana

Hi All,
I was trying to create sheets from Book1 to Book2. And used this code


Private oexcel As Excel.Application
Dim oSourceWorkBooks_1 As Excel.Workbooks
Dim oSourceWorkBook1 As Excel.Workbook

Dim oDestinationWorkBooks_1 As Excel.Workbooks
Dim oDestinationWorkBook_1 As Excel.Workbook
Dim oSourceWorkSheets_1 As Excel.Sheets

Dim oDataBaseSheet As Excel.Worksheet
Dim oTemplateSheet As Excel.Worksheet
Dim oDestinationWorkSheets_1 As Excel.Sheets
Dim oDestinationWorkSheet_1 As Excel.Worksheet


Sub New(ByVal file As String)
Dim filename As String = Path.Combine(Path.GetTempPath,
Path.GetTempFileName)
Dim _filename As String = ""
Dim b As Excel.Workbook

oexcel = CreateObject("Excel.Application")

oexcel.Visible = True
oexcel.DisplayAlerts = False
oDestinationWorkBooks_1 = oexcel.Workbooks
oDestinationWorkBook_1 = oDestinationWorkBooks_1.Add
oSourceWorkBooks_1 = oexcel.Workbooks

oSourceWorkBook1 = oSourceWorkBooks_1.Open(file)

oSourceWorkSheets_1 = oSourceWorkBook1.Sheets
oTemplateSheet = oSourceWorkSheets_1("Template")
oDataBaseSheet = oSourceWorkSheets_1("Database")

oDestinationWorkSheets_1 = oDestinationWorkBook_1.Sheets
oDestinationWorkSheet_1 = oDestinationWorkSheets_1("Sheet1")

'Copy sheets from Book1 to 2
For index As Integer = 1 To 10

oTemplateSheet.Copy(oDestinationWorkSheet_1)
Next


'End With
'oSourceWorkBook1 = oSourceWorkBooks1.Open(file)
marshal(oTemplateSheet)
marshal(oDataBaseSheet)
marshal(oSourceWorkSheets_1)
oSourceWorkSheets_1 = Nothing
oDataBaseSheet = Nothing
oTemplateSheet = Nothing

oSourceWorkBook1.Close()
marshal(oSourceWorkBooks_1)
marshal(oSourceWorkBook1)
oDestinationWorkBooks_1.Close()
marshal(oDestinationWorkBooks_1)
marshal(oDestinationWorkBook_1)
oexcel.Quit()
marshal(oexcel)
System.IO.File.Delete(filename)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oexcel)


Private Sub marshal(ByVal o As Object)
If Not o Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
o = Nothing
End If
End Sub


It was releasing correctly upto the marked . While I try to copy sheets
from WorkBook1 to WorkBook2 it was not releasing after adding that copy
method
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top