|
-
Sep 2nd, 2010, 06:52 AM
#1
Thread Starter
Addicted Member
closing excel (i know i know...)
i know this is a big problem for a lot of people and there are posts everywhere... but they aren't helping lol.
below, should this complete and close and terminate excel correctly? or am i missing something...
Code:
oExcel = CreateObject("Excel.Application")
oBooks = oExcel.Workbooks
oBook = oBooks.Open(Filename:="C:\Jared FC Project Desktop\fixture tracking.xls", UpdateLinks:=False, ReadOnly:=False)
oSheet = oBook.Worksheets(1)
oExcel.Visible = True
oSheet = Nothing
oBook.Close()
oBook = Nothing
oBooks.Close()
oBooks = Nothing
oExcel.Quit()
oExcel = Nothing
-
Sep 2nd, 2010, 07:51 AM
#2
Re: closing excel (i know i know...)
I'll still throw in ReleaseComObject here :
Code:
xlbook.Close
'...do the same as the following for range references if any, and all the excel stuff you've used...
System.Runtime.InteropServices.Marshal.ReleaseComObject(ws) 'the worksheet
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlbook) 'the workbook
xlapp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp) 'the application
VB.NET MVP 2008 - Present
-
Sep 2nd, 2010, 07:52 AM
#3
Re: closing excel (i know i know...)
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Sep 2nd, 2010, 07:58 AM
#4
Re: closing excel (i know i know...)
 Originally Posted by MarMan
What does it do?
I'm glad you asked. It so happens that MSDN has all the answers 
This method is used to explicitly control the lifetime of a COM object used from managed code. You should use this method to free the underlying COM object that holds references to resources in a timely manner or when objects must be freed in a specific order.
More info in the link
Then you can look up the documentation for the .Close method and see what the differences are.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Sep 2nd, 2010, 08:00 AM
#5
Thread Starter
Addicted Member
Re: closing excel (i know i know...)
well i haven't tried the code provided (im about to)
currently the excel process is still in task manager .... (yeah that crappy problem)
-
Sep 2nd, 2010, 08:24 AM
#6
Thread Starter
Addicted Member
Re: closing excel (i know i know...)
after the code below... the process still remains in task manager 
Code:
oExcel = CreateObject("Excel.Application")
oBooks = oExcel.Workbooks
oBook = oBooks.Open(Filename:="C:\Jared FC Project Desktop\fixture tracking.xls", UpdateLinks:=False, ReadOnly:=False)
oSheet = oBook.Worksheets(1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet) 'the worksheet
oBook.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook) 'the workbook
oBook = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel) 'the application
oExcel = Nothing
-
Sep 2nd, 2010, 03:48 PM
#7
Re: closing excel (i know i know...)
You could try killing the process:
Code:
For Each p As Process In Process.GetProcessesByName("excel")
p.Kill()
Next
Though that would close excel if the user had it running.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|