Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Playing with services

Playing with services

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeDelva
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • D DeDelva

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Read this[^]

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      D 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Read this[^]

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        D Offline
        D Offline
        DeDelva
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • D DeDelva

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • D 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 Kreskowiak

            D Offline
            D Offline
            DeDelva
            wrote on last edited by
            #5

            Hey 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
            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
            

            By the way nice link with the NAR Still don't know if i oversaw something? Thx D:thumbsup:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups