Playing with services
-
Hello All, I'm playing with interactions between excel and vb.net... Everytime i start an excel application it become's one of my processes in my taskbar. I always put my vars from workbook,sheets,app to nothing at the end i collect my garbage But wath do i forget to dispose this from the services?? I'm kind a noob so can somebody provide me some help? I just want to clean up after using...
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()Thx in advance
-
Hello All, I'm playing with interactions between excel and vb.net... Everytime i start an excel application it become's one of my processes in my taskbar. I always put my vars from workbook,sheets,app to nothing at the end i collect my garbage But wath do i forget to dispose this from the services?? I'm kind a noob so can somebody provide me some help? I just want to clean up after using...
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()Thx in advance
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
A guide to posting questions on CodeProject[^]
Dave KreskowiakHey, Thx Dave it was a really helpfull article. Can you check if i forget something?(maybe in my catch blok or something?)
Dim oApp As New Excel.Application() Dim oBook As Excel.Workbook = oApp.Workbooks.Add Dim oSheet As Excel.Worksheet = oApp.ActiveSheet Dim chartRange As Excel.Range 'hoofding chartRange = oSheet.Range("A1", "I1") chartRange.Merge() chartRange.FormulaR1C1 = "WorkBook" chartRange.Font.Bold = True chartRange.Font.Size = 20 chartRange.HorizontalAlignment = 3 'chartRange.VerticalAlignment = 3 'Save the Workbook oBook.SaveAs(sSampleFolder & "V.F." & idvoorexcel & "-" & Label6.Text & ".xlsx") oSheet = Nothing oBook.Close(False) oBook = Nothing oApp.Quit() oApp = Nothing System.Threading.Thread.Sleep(3000) End If Catch ex As Exception MsgBox("location : catch blok") oSheet = Nothing oBook = Nothing End Try
Greetings
-
Hey, Thx Dave it was a really helpfull article. Can you check if i forget something?(maybe in my catch blok or something?)
Dim oApp As New Excel.Application() Dim oBook As Excel.Workbook = oApp.Workbooks.Add Dim oSheet As Excel.Worksheet = oApp.ActiveSheet Dim chartRange As Excel.Range 'hoofding chartRange = oSheet.Range("A1", "I1") chartRange.Merge() chartRange.FormulaR1C1 = "WorkBook" chartRange.Font.Bold = True chartRange.Font.Size = 20 chartRange.HorizontalAlignment = 3 'chartRange.VerticalAlignment = 3 'Save the Workbook oBook.SaveAs(sSampleFolder & "V.F." & idvoorexcel & "-" & Label6.Text & ".xlsx") oSheet = Nothing oBook.Close(False) oBook = Nothing oApp.Quit() oApp = Nothing System.Threading.Thread.Sleep(3000) End If Catch ex As Exception MsgBox("location : catch blok") oSheet = Nothing oBook = Nothing End Try
Greetings
Yeah, I see no mention of
Marshal.ReleaseComObject()
. You might want to go back and re-read the article.A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Yeah, I see no mention of
Marshal.ReleaseComObject()
. You might want to go back and re-read the article.A guide to posting questions on CodeProject[^]
Dave KreskowiakHey i'm back from a student holiday Thx for all the answers i will vote 4 them... I posted the wrong code snippet here is the code that i wanted to post :
Imports Microsoft.Office.Interop
TryDim 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
By the way nice link with the NAR Still don't know if i oversaw something? Thx D:thumbsup: