Results 1 to 8 of 8

Thread: [RESOLVED] Trouble closing EXCEL.exe COM instances

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    61

    Resolved [RESOLVED] Trouble closing EXCEL.exe COM instances

    Hello VB world!

    This is my first post so forgive me if I don't supply enough information to my problem first time round. I'm still very much in the learning stage meaning that I have a general understanding of most of my code and part of it is made up from google searches to get me where I am with a small reporting application I'm building.

    I have a function which I call below which initializes a new instance of EXCEL.exe in task manager. I'm having trouble disposing of this instance at the end of my function.

    If I use
    Code:
    excelApplication.Quit()
            Marshal.ReleaseComObject(excelApplication)
    right after I initialize the instance then it gets rid of it no problem. However at the end of my function it is not working. I have done a bit of searching on google before I came here and it basically says I have to release all instances of the com object but I can't work out what they are or if there is a better way to do it or find out. Hoping this is an easy one for someone else; it's been driving me mad for about 3 hours :O

    Code:
    Dim excelApplication As New excel.Application
    
    
    
    
            Dim fileInfo1 As New System.IO.FileInfo(XLSXFile)
            If fileInfo1.Exists Then
                SetAttr(XLSXFile, vbNormal)
                fileInfo1.Delete()
            End If
    
            Dim fxml As New System.IO.FileInfo(XMLFile)
            If fxml.Exists Then
                excelApplication.Workbooks.Open(XMLFile)
                excelApplication.Workbooks.Item(1).CheckCompatibility = True
                excelApplication.DisplayAlerts = False
                excelApplication.Workbooks.Item(1).SaveAs(XLSXFile, excel.XlFileFormat.xlWorkbookDefault)
                excelApplication.DisplayAlerts = False
                excelApplication.Workbooks.Close()
                SetAttr(XMLFile, vbNormal)
                fxml.Delete()
    
                'Else
                '    MessageBox.Show("XML File does not exists")
            End If
    
            Dim fileInfo2 As New System.IO.FileInfo(XLSXFile)
            If fileInfo2.Exists Then
                SetAttr(XLSXFile, FileAttribute.Normal)
            End If
    
    
    
            excelApplication.Quit()
            Marshal.ReleaseComObject(excelApplication)
    Edit: The function takes an XML document and converts it to an XLSX document
    Last edited by VB.NETGAL; Apr 10th, 2013 at 02:50 PM. Reason: more information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width