Question Playing with Interop (excel)

eliow

New member
Joined
Oct 26, 2011
Messages
1
Programming Experience
1-3
Code peepz,

I'm writing excel files from vb. That's no problem...

But i have problems with closing my excel services in my task manager. Before i wan to close my pc i get prompt with the question to save workbook1,....

You can see my code can anybody tell me where i don't close my excel service?

am i overseeing something or completely wrong?

thx in advance

<pre>
Imports Microsoft.Office.Interop
Try

Dim oApp As New Excel.Application()
Dim oBook As Excel.Workbook = oApp.Workbooks.Add
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet

chartRange = oSheet.range("A20", "G20")
oSheet.Range("A20").Value = "blabla"
chartRange.BorderAround(Excel.XlLineStyle.xlContinuous, _
Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex. _
xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic)

'Save the Workbook and quit Excel.
oBook.SaveAs(sSampleFolder & "V.F." & idvoorexcel & "-" & Label6.Text & "-" & DateTime.Now.ToString("ddMMyyHHmmss") & ".xlsx")
oSheet = Nothing
NAR(oSheet)
oBook.Close(False)
NAR(oBook)
oBook = Nothing
oApp.Quit()
NAR(oApp)
oApp = Nothing
System.Threading.Thread.Sleep(1500)
End If
Catch ex As Exception
NAR(oSheet)
oBook.Close(False)
NAR(oBook)
oSheet = Nothing
oBook.Close(False)
oBook = Nothing
System.Threading.Thread.Sleep(1500)
GC.Collect()
End Try
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
</pre>
 
Last edited:
Back
Top