PC Review


Reply
Thread Tools Rate Thread

Desperately trying to close Excel!!!! Gurus help needed

 
 
Atchoum
Guest
Posts: n/a
 
      17th Aug 2004
Hi,

(Sorry if this is a repost but I don't see my original post in the
newsgroup).

I am trying to open Excel, perform certain operations then leave it open so
that the user can close it whenever he wants. The problem is that Excel will
remain open when I close it manually. After hours of testing, I am down to
this:
the line s = Range.FindNext(s) below is the one causing problem. If I
comment it out, when I close Excel manually, it does close completely. If I
remove the comment, then Excel will not close.
Anyone has a solution for this?

Desperately yours,

Atchoum


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
oExcel = CreateObject("Excel.Application")
oWorkbook = oExcel.Workbooks.Open(Application.StartupPath &
"\test.xls)
For i = 1 To oWorkbook.Sheets.Count
Range = oWorkbook.Sheets(i).UsedRange
s = Range.Find("[[C:", lookin:=-4163) 'xlValues
If Not s Is Nothing Then
sFirstAddress = s.Address
Do
s = Range.FindNext(s) ' <------- Line that makes
Excel remain open after manually closing it ---------->
Loop While Not s Is Nothing And s.Address <>
sFirstAddress
End If
Next i
oExcel.Visible = True
NAR(s)
NAR(oWorkbook)
oExcel = Nothing
NAR(oExcel)
GC.Collect()
End Sub

Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub


 
Reply With Quote
 
 
 
 
Jorge
Guest
Posts: n/a
 
      17th Aug 2004
(well reposting my answer)
Hi Atchoum

Once you use NAR excel will be closed when you close the
form that called it even though you used ReleaseComObject.
I think its because the form has still a reference to
excel.

Another approach that i use is to get the excel process
ID when you create it and kill it manually using the
process class.

Kind Regards
Jorge


>-----Original Message-----
>Hi,
>
>(Sorry if this is a repost but I don't see my original

post in the
>newsgroup).
>
>I am trying to open Excel, perform certain operations

then leave it open so
>that the user can close it whenever he wants. The

problem is that Excel will
>remain open when I close it manually. After hours of

testing, I am down to
>this:
>the line s = Range.FindNext(s) below is the one causing

problem. If I
>comment it out, when I close Excel manually, it does

close completely. If I
>remove the comment, then Excel will not close.
>Anyone has a solution for this?
>
>Desperately yours,
>
>Atchoum
>
>
> Private Sub Button1_Click(ByVal sender As

System.Object, ByVal e As
>System.EventArgs) Handles Button1.Click
> oExcel = CreateObject("Excel.Application")
> oWorkbook = oExcel.Workbooks.Open

(Application.StartupPath &
>"\test.xls)
> For i = 1 To oWorkbook.Sheets.Count
> Range = oWorkbook.Sheets(i).UsedRange
> s = Range.Find("[[C:", lookin:=-

4163) 'xlValues
> If Not s Is Nothing Then
> sFirstAddress = s.Address
> Do
> s = Range.FindNext(s) ' <-------

Line that makes
>Excel remain open after manually closing it ---------->
> Loop While Not s Is Nothing And

s.Address <>
>sFirstAddress
> End If
> Next i
> oExcel.Visible = True
> NAR(s)
> NAR(oWorkbook)
> oExcel = Nothing
> NAR(oExcel)
> GC.Collect()
> End Sub
>
> Private Sub NAR(ByVal o As Object)
> Try
>

System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
> Catch
> Finally
> o = Nothing
> End Try
> End Sub
>
>
>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help desperately needed with excel charts djewkes Microsoft Excel Misc 10 2nd Jul 2009 10:52 PM
Help needed desperately with excel data djewkes Microsoft Word Document Management 1 30th Jun 2009 02:56 PM
Excel Formula Desperately Needed! ThunderStorm Studio Microsoft Excel Misc 2 26th Feb 2008 10:13 PM
Excel VBA Gurus needed Career Capital Microsoft Excel Misc 0 9th Sep 2005 05:46 AM
Desperately trying to close Excel!!!! Gurus help needed Atchoum Microsoft VB .NET 3 17th Aug 2004 03:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:32 AM.