COM Interop Excel: Let the user quit the application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asedt
    New Member
    • Jun 2008
    • 130

    COM Interop Excel: Let the user quit the application

    I made this progarm in Visual studio 2005 vith COM Interop, I want to change the program so it does'n turn of excel and let the user control the application insted after the macro have run.

    Code:
            Dim oExcel As Excel.Application
            Dim oBook As Excel.Workbook
            Dim oBooks As Excel.Workbooks
    
            'Start excel
            oExcel = CreateObject("Excel.Application")
            oExcel.Visible = True
            oBooks = oExcel.Workbooks
    
            'Walkaround för bug
            'http://support.microsoft.com/default.aspx?scid=kb;en-us;320369
            Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
            System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
    
    
            oBook = oBooks.Open("C:\ASEDT.xls")
    
            'Run macro / sub rutine
            oExcel.Run("MyOpen", parameter)
    
            'Close the wokbook and quit Excel
    
           oBook.Close(False)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
            oBook = Nothing
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
            oBooks = Nothing
            oExcel.Quit()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
            oExcel = Nothing
    
            'Walkaround för bug
            System.Threading.Thread.CurrentThread.CurrentCulture = oldCI

    What lines to remowe?? i guess those marked with: <--**


    Code:
           oBook.Close(False) <--**
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
            oBook = Nothing
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
            oBooks = Nothing
            oExcel.Quit() <--**
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
            oExcel = Nothing
  • asedt
    New Member
    • Jun 2008
    • 130

    #2
    Still nothing.. :(


    I guess that i need to free the Objets in the program to avoid some memory leaks? but don't "turn off the excel objects". Is my thinking somewath right?

    Comment

    Working...