Results 1 to 10 of 10

Thread: [RESOLVED] Closing Excel

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Resolved [RESOLVED] Closing Excel

    Okay so my program opens excel, reads a few cells, and closes excel. But, it does not fully close excel and after multiple runs, I have multiple EXCEL.EXE *32 in my process list. It also asks for a save when it's closing when there are no changes being made, is there any way to avoid this? And how do you get Excel to fully close?

    Imports Excel = Microsoft.Office.Interop.Excel
    vb Code:
    1. Public Sub XLMain()
    2.         xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
    3.         xlBook = xlApp.Workbooks.Open(strExcelPath)
    4.         xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
    5.         'Stuffs to be did
    6.         ReadXL()
    7.         ImportXL()
    8.         'Close Excel:
    9.         CloseExcel()
    10.     End Sub
    11.     Public Sub CloseExcel()
    12.         xlBook.Close()
    13.         xlApp.Quit()
    14.     End Sub
    15.     Public Sub ReadXL()
    16.         Try
    17.             ordernumber = xlSheet.Cells(5, "C").Value.ToString
    18.             owner1 = xlSheet.Cells(6, "C").Value.ToString
    19.             county = xlSheet.Cells(6, "I").Value.ToString
    20.             fulladdress = xlSheet.Cells(7, "C").Value.ToString
    21.             address = Mid(fulladdress, 1, InStr(fulladdress, ",") - 1)
    22.             halfaddress = Mid(fulladdress, address.Length + 2)
    23.             zip = Mid(fulladdress, fulladdress.Length - 4, 5)
    24.             city = Mid(halfaddress, 1, InStr(halfaddress, ",") - 1)
    25.             state = Mid(fulladdress, address.Length + city.Length + 4, 2)
    26.         Catch ex As Exception
    27.             MsgBox(ex.ToString)
    28.         End Try
    29.     End Sub

    I also just tried this, and it did not work:
    vb Code:
    1. Public Sub CloseExcel()
    2.         'xlBook.Close()
    3.         'xlApp.Quit()
    4.         System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
    5.         GC.Collect()
    6.     End Sub

    Just tried this also, and it did not work:
    vb Code:
    1. Dim strExcelPath As String = "C:\Users\Aj\Desktop\Tax_Research_Template_2010_-_Excel.xls"
    2.     Dim xlApp = New Excel.Application()
    3.     Dim xlWbs = xlApp.Workbooks
    4.     Dim xlBook = xlWbs.Open(strExcelPath)
    5.     Dim xlSheet = xlBook.Worksheets(1)
    6.     Public Sub CloseExcel()
    7.         xlBook.Close()
    8.         xlApp.Quit()
    9.         xlBook = Nothing
    10.         xlWbs = Nothing
    11.         xlApp = Nothing
    12.     End Sub
    The program closes, without asking for a save, gets me the data I need, but remains in the process list.
    Using this for my Imports
    Code:
    Imports Excel = Microsoft.Office.Interop.Excel
    Last edited by thebuffalo; May 23rd, 2012 at 12:29 PM.

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