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 useright 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 :OCode:excelApplication.Quit() Marshal.ReleaseComObject(excelApplication)
Edit: The function takes an XML document and converts it to an XLSX documentCode: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)




Reply With Quote