473,513 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't destroy Excel Process; tried Just about everything!

LP
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
..NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs
in the taks manager' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
'API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub
Nov 21 '05 #1
16 4529
..NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
.NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs
in the taks manager' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
'API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub

Nov 21 '05 #2
LP
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end of your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
.NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs in the taks manager' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
'API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"

(ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub


Nov 21 '05 #3
Don't forget to call Marshall.ReleaseComObject(yourXLinstanceObjectVari able)
for EACH COM object you've instanced after you quit Excel.

"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process
is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end

of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I am trying to use .NET with Excel. I installed Office 2003 and
> selected
> .NET programming suport option, so it installed all those PIA, as MS
> sugests. But I can not find a way to destroy Excel process, it still hangs > in the taks manager' Processes as running. I am trying very simple code
> (see below), but Excel wont go away, I tried just about anything I
> could
> find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
> NOTHING works, Any help will be appreciated.
> 'API declaration:
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal > lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"

(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
> Long) As Long
>
> ' actual VB.NET Code:
>
> Public Const WM_DESTROY = &H2
>
> Public Const WM_USER = &H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption = "Microsoft Excel (to close)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
> Dim settings As New SiteSettings
>
> Dim dir As String = settings.getAppSettingValue("TempDirectory")
>
> Dim fileName As String = dir & Session.SessionID & ".xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk = Nothing
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> ' Kill process
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>
> If hwnd <> 0 Then
>
> lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>
> lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>
> End If
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
> Try
>
> While (i <> 0 And i <> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
> End While
>
> Catch
>
> Finally
>
> o = Nothing
>
> End Try
>
> End Sub
>
>



Nov 21 '05 #4
LP
Yes, I am doing that with NAR() function:

NAR(wrk)
Private Sub NAR(ByRef o As Object)
Dim i As Integer = -2
Try
While (i <> 0 And i <> -1)
i =
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch
Finally
o = Nothing
End Try
End Sub
"Scott M." <s-***@nospam.nospam> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Don't forget to call Marshall.ReleaseComObject(yourXLinstanceObjectVari able) for EACH COM object you've instanced after you quit Excel.

"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end
of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I am trying to use .NET with Excel. I installed Office 2003 and
> selected
> .NET programming suport option, so it installed all those PIA, as MS
> sugests. But I can not find a way to destroy Excel process, it still

hangs
> in the taks manager' Processes as running. I am trying very simple

code > (see below), but Excel wont go away, I tried just about anything I
> could
> find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But > NOTHING works, Any help will be appreciated.
> 'API declaration:
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"

(ByVal
> lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As > Long) As Long
>
> ' actual VB.NET Code:
>
> Public Const WM_DESTROY = &H2
>
> Public Const WM_USER = &H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption = "Microsoft Excel (to close)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
> Dim settings As New SiteSettings
>
> Dim dir As String = settings.getAppSettingValue("TempDirectory")
>
> Dim fileName As String = dir & Session.SessionID & ".xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk = Nothing
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> ' Kill process
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>
> If hwnd <> 0 Then
>
> lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>
> lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>
> End If
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
> Try
>
> While (i <> 0 And i <> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
> End While
>
> Catch
>
> Finally
>
> o = Nothing
>
> End Try
>
> End Sub
>
>



Nov 21 '05 #5
LP,

I spent a few weeks dealing with the same thing. I finally discovered that
how Excel objects are created and the order in which Excel objects are
disposed is critical to getting the Excel Process to terminate.

Try the following. the code opens a new instance of excel, adds a workbook,
adds some sheets to the workbook, then adds some data to the first row of
each sheet. Then it saves and exits

Dim r, c, s as Integer

Dim xl As Excel.Application

Dim wbs As Excel.Workbooks

Dim wb As Excel.Workbook

Dim ws As Excel.Worksheet

Dim rng As Excel.Range

Dim st As Excel.Sheets

Dim SName() As String = {"First", "Second", "Third", "Fourth"}

Dim settings As New SiteSettings
Dim dir As String = settings.getAppSettingValue("TempDirectory")
Dim fileName As String = dir & Session.SessionID & ".xls"

r = 1

xl = New Excel.Application

xl.Visible = False

xl.DisplayAlerts = False

xl.SheetsInNewWorkbook = 1

wbs = xl.Workbooks

wb = wbs.Add

st = wb.Sheets

ws = wb.ActiveSheet

ws.Name = "Summary"

For s = 0 To Sname.Length

st.Add()

ws = wb.ActiveSheet

ws.Name = Sname(s)

For c = 1 To 10

ws.Cells.Item(r, c) = ¡°X¡±

Next

Next

xl.ActiveWorkbook.SaveAs(filename)

xl.ActiveWorkbook.Saved = True

NAR(rng)

NAR(st)

NAR(ws)

xl.ActiveWorkbook.Close()

NAR(wb)

NAR(wbs)

xl.Quit()

NAR(xl)

GC.Collect()

Private Sub NAR(ByVal o As Object)

Dim i, j As Integer

Try

For i = 1 To
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

j =
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

Next

Catch

Finally

o = Nothing

End Try

End Sub
Let me know how it goes!

HTH
Lee
"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process
is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end

of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I am trying to use .NET with Excel. I installed Office 2003 and
> selected
> .NET programming suport option, so it installed all those PIA, as MS
> sugests. But I can not find a way to destroy Excel process, it still hangs > in the taks manager' Processes as running. I am trying very simple code
> (see below), but Excel wont go away, I tried just about anything I
> could
> find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
> NOTHING works, Any help will be appreciated.
> 'API declaration:
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal > lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"

(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
> Long) As Long
>
> ' actual VB.NET Code:
>
> Public Const WM_DESTROY = &H2
>
> Public Const WM_USER = &H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption = "Microsoft Excel (to close)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
> Dim settings As New SiteSettings
>
> Dim dir As String = settings.getAppSettingValue("TempDirectory")
>
> Dim fileName As String = dir & Session.SessionID & ".xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk = Nothing
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> ' Kill process
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>
> If hwnd <> 0 Then
>
> lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>
> lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>
> End If
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
> Try
>
> While (i <> 0 And i <> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
> End While
>
> Catch
>
> Finally
>
> o = Nothing
>
> End Try
>
> End Sub
>
>



Nov 21 '05 #6
LP
Thanks lgbjr.

I tried your code, but unfortunatly it's still not working. I even tried
enchancing your code; destroying selected range and , looping through
worksheets and workbooks in xl application and destroying them and still
doesnt work. It seems to me it's somekind of bug in Excel.Interop, I really
want to hear from MS people about this. MSDN library doesn't seem to have
any usefull info about this issue.
"lgbjr" <lg***@online.nospam> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
LP,

I spent a few weeks dealing with the same thing. I finally discovered that
how Excel objects are created and the order in which Excel objects are
disposed is critical to getting the Excel Process to terminate.

Try the following. the code opens a new instance of excel, adds a workbook, adds some sheets to the workbook, then adds some data to the first row of
each sheet. Then it saves and exits

Dim r, c, s as Integer

Dim xl As Excel.Application

Dim wbs As Excel.Workbooks

Dim wb As Excel.Workbook

Dim ws As Excel.Worksheet

Dim rng As Excel.Range

Dim st As Excel.Sheets

Dim SName() As String = {"First", "Second", "Third", "Fourth"}

Dim settings As New SiteSettings
Dim dir As String = settings.getAppSettingValue("TempDirectory")
Dim fileName As String = dir & Session.SessionID & ".xls"

r = 1

xl = New Excel.Application

xl.Visible = False

xl.DisplayAlerts = False

xl.SheetsInNewWorkbook = 1

wbs = xl.Workbooks

wb = wbs.Add

st = wb.Sheets

ws = wb.ActiveSheet

ws.Name = "Summary"

For s = 0 To Sname.Length

st.Add()

ws = wb.ActiveSheet

ws.Name = Sname(s)

For c = 1 To 10

ws.Cells.Item(r, c) = ¡°X¡±

Next

Next

xl.ActiveWorkbook.SaveAs(filename)

xl.ActiveWorkbook.Saved = True

NAR(rng)

NAR(st)

NAR(ws)

xl.ActiveWorkbook.Close()

NAR(wb)

NAR(wbs)

xl.Quit()

NAR(xl)

GC.Collect()

Private Sub NAR(ByVal o As Object)

Dim i, j As Integer

Try

For i = 1 To
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

j =
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

Next

Catch

Finally

o = Nothing

End Try

End Sub
Let me know how it goes!

HTH
Lee
"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Thanks for the reply. I actually already had .Collect() below. I added:
GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process is
running. Any other ideas?



"Howard Kaikow" <ka****@standards.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
.NET languages do nopt clean up the same way as VBA does.

In addition to setting variables to Nothing, add the following at the end
of
your code to expedite garbage collection.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()

And do not forget to Quit Excel.

--
http://www.standards.com/; See Howard Kaikow's web site.
"LP" <lp@a.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I am trying to use .NET with Excel. I installed Office 2003 and
> selected
> .NET programming suport option, so it installed all those PIA, as MS
> sugests. But I can not find a way to destroy Excel process, it still

hangs
> in the taks manager' Processes as running. I am trying very simple

code > (see below), but Excel wont go away, I tried just about anything I
> could
> find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But > NOTHING works, Any help will be appreciated.
> 'API declaration:
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"

(ByVal
> lpClassName As String, ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal
> hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As > Long) As Long
>
> ' actual VB.NET Code:
>
> Public Const WM_DESTROY = &H2
>
> Public Const WM_USER = &H400
>
> Dim exApplication As New Excel.Application
>
> exApplication.DisplayAlerts = False
>
> exApplication.Caption = "Microsoft Excel (to close)"
>
> Dim wrk As Excel.Workbook
>
> wrk = exApplication.Workbooks.Add()
>
> Dim settings As New SiteSettings
>
> Dim dir As String = settings.getAppSettingValue("TempDirectory")
>
> Dim fileName As String = dir & Session.SessionID & ".xls"
>
> wrk.SaveAs(fileName)
>
> wrk.Close()
>
> NAR(wrk)
>
> wrk = Nothing
>
> exApplication.Quit()
>
> NAR(exApplication)
>
> exApplication = Nothing
>
> ' Kill process
>
> Dim hwnd As Long
>
> Dim lngResult As Long
>
> hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>
> If hwnd <> 0 Then
>
> lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>
> lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>
> End If
>
>
>
> Private Sub NAR(ByRef o As Object)
>
> Dim i As Integer = -2
>
> Try
>
> While (i <> 0 And i <> -1)
>
> i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>
> End While
>
> Catch
>
> Finally
>
> o = Nothing
>
> End Try
>
> End Sub
>
>



Nov 21 '05 #7
Hmm,

For me, it does work. And believe me, I tried many different iteration over
the course of a few weeks trying to get rid of the Excel process. Hopefully
MS will have some additional info, other than the MSDN article with the NAR
function.

Actually, I haven't worked on that part of my code in some time. I'll have
to run it and verify that it does actually work. I have it marked as
completed on my task list. But, maybe, that was done too soon (and I just
got tired of working on it :-))

I'll let you know.

cheers
Lee

"LP" <lp@a.com> wrote in message
news:eE**************@TK2MSFTNGP14.phx.gbl...
Thanks lgbjr.

I tried your code, but unfortunatly it's still not working. I even tried
enchancing your code; destroying selected range and , looping through
worksheets and workbooks in xl application and destroying them and still
doesnt work. It seems to me it's somekind of bug in Excel.Interop, I
really
want to hear from MS people about this. MSDN library doesn't seem to have
any usefull info about this issue.
"lgbjr" <lg***@online.nospam> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
LP,

I spent a few weeks dealing with the same thing. I finally discovered
that
how Excel objects are created and the order in which Excel objects are
disposed is critical to getting the Excel Process to terminate.

Try the following. the code opens a new instance of excel, adds a

workbook,
adds some sheets to the workbook, then adds some data to the first row of
each sheet. Then it saves and exits

Dim r, c, s as Integer

Dim xl As Excel.Application

Dim wbs As Excel.Workbooks

Dim wb As Excel.Workbook

Dim ws As Excel.Worksheet

Dim rng As Excel.Range

Dim st As Excel.Sheets

Dim SName() As String = {"First", "Second", "Third", "Fourth"}

Dim settings As New SiteSettings
Dim dir As String = settings.getAppSettingValue("TempDirectory")
Dim fileName As String = dir & Session.SessionID & ".xls"

r = 1

xl = New Excel.Application

xl.Visible = False

xl.DisplayAlerts = False

xl.SheetsInNewWorkbook = 1

wbs = xl.Workbooks

wb = wbs.Add

st = wb.Sheets

ws = wb.ActiveSheet

ws.Name = "Summary"

For s = 0 To Sname.Length

st.Add()

ws = wb.ActiveSheet

ws.Name = Sname(s)

For c = 1 To 10

ws.Cells.Item(r, c) = ¡°X¡±

Next

Next

xl.ActiveWorkbook.SaveAs(filename)

xl.ActiveWorkbook.Saved = True

NAR(rng)

NAR(st)

NAR(ws)

xl.ActiveWorkbook.Close()

NAR(wb)

NAR(wbs)

xl.Quit()

NAR(xl)

GC.Collect()

Private Sub NAR(ByVal o As Object)

Dim i, j As Integer

Try

For i = 1 To
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

j =
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

Next

Catch

Finally

o = Nothing

End Try

End Sub
Let me know how it goes!

HTH
Lee
"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
> Thanks for the reply. I actually already had .Collect() below. I added:
> GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process > is
> running. Any other ideas?
>
>
>
>
>
>
>
> "Howard Kaikow" <ka****@standards.com> wrote in message
> news:Oo**************@TK2MSFTNGP10.phx.gbl...
>> .NET languages do nopt clean up the same way as VBA does.
>>
>> In addition to setting variables to Nothing, add the following at the end > of
>> your code to expedite garbage collection.
>> GC.Collect()
>> GC.WaitForPendingFinalizers()
>> GC.Collect()
>> GC.WaitForPendingFinalizers()
>>
>> And do not forget to Quit Excel.
>>
>> --
>> http://www.standards.com/; See Howard Kaikow's web site.
>> "LP" <lp@a.com> wrote in message
>> news:uO**************@TK2MSFTNGP12.phx.gbl...
>> > Hello,
>> >
>> > I am trying to use .NET with Excel. I installed Office 2003 and
>> > selected
>> > .NET programming suport option, so it installed all those PIA, as MS
>> > sugests. But I can not find a way to destroy Excel process, it still
> hangs
>> > in the taks manager' Processes as running. I am trying very simple code >> > (see below), but Excel wont go away, I tried just about anything I
>> > could
>> > find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But >> > NOTHING works, Any help will be appreciated.
>> > 'API declaration:
>> > Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
> (ByVal
>> > lpClassName As String, ByVal lpWindowName As String) As Long
>> >
>> > Public Declare Function SendMessage Lib "user32" Alias
>> > "SendMessageA"
>> (ByVal
>> > hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As >> > Long) As Long
>> >
>> > ' actual VB.NET Code:
>> >
>> > Public Const WM_DESTROY = &H2
>> >
>> > Public Const WM_USER = &H400
>> >
>> > Dim exApplication As New Excel.Application
>> >
>> > exApplication.DisplayAlerts = False
>> >
>> > exApplication.Caption = "Microsoft Excel (to close)"
>> >
>> > Dim wrk As Excel.Workbook
>> >
>> > wrk = exApplication.Workbooks.Add()
>> >
>> > Dim settings As New SiteSettings
>> >
>> > Dim dir As String = settings.getAppSettingValue("TempDirectory")
>> >
>> > Dim fileName As String = dir & Session.SessionID & ".xls"
>> >
>> > wrk.SaveAs(fileName)
>> >
>> > wrk.Close()
>> >
>> > NAR(wrk)
>> >
>> > wrk = Nothing
>> >
>> > exApplication.Quit()
>> >
>> > NAR(exApplication)
>> >
>> > exApplication = Nothing
>> >
>> > ' Kill process
>> >
>> > Dim hwnd As Long
>> >
>> > Dim lngResult As Long
>> >
>> > hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>> >
>> > If hwnd <> 0 Then
>> >
>> > lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>> >
>> > lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>> >
>> > End If
>> >
>> >
>> >
>> > Private Sub NAR(ByRef o As Object)
>> >
>> > Dim i As Integer = -2
>> >
>> > Try
>> >
>> > While (i <> 0 And i <> -1)
>> >
>> > i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>> >
>> > End While
>> >
>> > Catch
>> >
>> > Finally
>> >
>> > o = Nothing
>> >
>> > End Try
>> >
>> > End Sub
>> >
>> >
>>
>>
>
>



Nov 21 '05 #8
Something tells me that it's the way you've got the NAR method setup that is
the problem.

Also, you should be setting your object variable to nothing before you call
Marsahall.ReleaseComObject:

"The ReleaseComObject method decrements the reference count of a runtime
callable wrapper. When the reference count reached zero, the runtime
releases all its references on the unmanaged COM object, and throws a
System.NullReferenceException if you attempt to use the object further."

Have you tried just using ReleaseCom object directly in your code rather
than trying to create a "kill all" method?

"LP" <lp@a.com> wrote in message
news:uT**************@TK2MSFTNGP15.phx.gbl...
Yes, I am doing that with NAR() function:

NAR(wrk)
Private Sub NAR(ByRef o As Object)
Dim i As Integer = -2
Try
While (i <> 0 And i <> -1)
i =
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch
Finally
o = Nothing
End Try
End Sub
"Scott M." <s-***@nospam.nospam> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
Don't forget to call

Marshall.ReleaseComObject(yourXLinstanceObjectVari able)
for EACH COM object you've instanced after you quit Excel.

"LP" <lp@a.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
> Thanks for the reply. I actually already had .Collect() below. I added:
> GC.Collect() GC.WaitForPendingFinalizers() twice, but still Excel Process > is
> running. Any other ideas?
>
>
>
>
>
>
>
> "Howard Kaikow" <ka****@standards.com> wrote in message
> news:Oo**************@TK2MSFTNGP10.phx.gbl...
>> .NET languages do nopt clean up the same way as VBA does.
>>
>> In addition to setting variables to Nothing, add the following at the end > of
>> your code to expedite garbage collection.
>> GC.Collect()
>> GC.WaitForPendingFinalizers()
>> GC.Collect()
>> GC.WaitForPendingFinalizers()
>>
>> And do not forget to Quit Excel.
>>
>> --
>> http://www.standards.com/; See Howard Kaikow's web site.
>> "LP" <lp@a.com> wrote in message
>> news:uO**************@TK2MSFTNGP12.phx.gbl...
>> > Hello,
>> >
>> > I am trying to use .NET with Excel. I installed Office 2003 and
>> > selected
>> > .NET programming suport option, so it installed all those PIA, as MS
>> > sugests. But I can not find a way to destroy Excel process, it still
> hangs
>> > in the taks manager' Processes as running. I am trying very simple code >> > (see below), but Excel wont go away, I tried just about anything I
>> > could
>> > find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But >> > NOTHING works, Any help will be appreciated.
>> > 'API declaration:
>> > Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
> (ByVal
>> > lpClassName As String, ByVal lpWindowName As String) As Long
>> >
>> > Public Declare Function SendMessage Lib "user32" Alias
>> > "SendMessageA"
>> (ByVal
>> > hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As >> > Long) As Long
>> >
>> > ' actual VB.NET Code:
>> >
>> > Public Const WM_DESTROY = &H2
>> >
>> > Public Const WM_USER = &H400
>> >
>> > Dim exApplication As New Excel.Application
>> >
>> > exApplication.DisplayAlerts = False
>> >
>> > exApplication.Caption = "Microsoft Excel (to close)"
>> >
>> > Dim wrk As Excel.Workbook
>> >
>> > wrk = exApplication.Workbooks.Add()
>> >
>> > Dim settings As New SiteSettings
>> >
>> > Dim dir As String = settings.getAppSettingValue("TempDirectory")
>> >
>> > Dim fileName As String = dir & Session.SessionID & ".xls"
>> >
>> > wrk.SaveAs(fileName)
>> >
>> > wrk.Close()
>> >
>> > NAR(wrk)
>> >
>> > wrk = Nothing
>> >
>> > exApplication.Quit()
>> >
>> > NAR(exApplication)
>> >
>> > exApplication = Nothing
>> >
>> > ' Kill process
>> >
>> > Dim hwnd As Long
>> >
>> > Dim lngResult As Long
>> >
>> > hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")
>> >
>> > If hwnd <> 0 Then
>> >
>> > lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)
>> >
>> > lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)
>> >
>> > End If
>> >
>> >
>> >
>> > Private Sub NAR(ByRef o As Object)
>> >
>> > Dim i As Integer = -2
>> >
>> > Try
>> >
>> > While (i <> 0 And i <> -1)
>> >
>> > i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)
>> >
>> > End While
>> >
>> > Catch
>> >
>> > Finally
>> >
>> > o = Nothing
>> >
>> > End Try
>> >
>> > End Sub
>> >
>> >
>>
>>
>
>



Nov 21 '05 #9
Is the Google Desktop installed? For some weird reason, its presence
prevents Excel to exit.

/Fredrik
Nov 21 '05 #10
I've never had much luck getting OFFICE apps to run down cleanly and
consistently.

My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)

The time frame between 1 and 3 must be as short as possible.
Sanity check the process name if the above makes you uncomfortable.

Then once you have tried every trick you can think of to tell EXCEL to
shut down in a nice way, then you can see if/when the process has exited
with the .NET "Process" object. Give it a moment or two. If it still has
not gone away, then kill it!

To me, there seems to be too much voodoo in getting office automation to
avoid leaving orphaned processes out there.

HTH - Lee
Nov 21 '05 #11
LP
Thanks Lee,
My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)
What do you mean scan process, could elaborate on this? Any code snippets
would be nice.

I did get it to work to certain point; just to open a file, add a workbook
and "save as" it. From everyone's comments on this thread and from my own
painful experience, I did figure out the pattern behind cleaning up excel.
Basically ReleaseComObject everything that excel object "touches" even if
it's not obvious. For example my code never directly referenced worksheets
collection, but I did referenced workbooks, but I still had to get reference
to worksheets and ReleaseComObject it to kill excel process. I guess
underneath the covers workbooks object creates worksheets reference.

So I got that part to work, but when I started actually writing data to
excel, I quickly realized it's not going to be worth my time. Because I
literally had to Release every cell I referenced. And even then I could miss
something not so obvious.

So I decided to do all excel related work in classic asp. I wasn't too happy
about going back to old scripting world, but it worked out beautifully for
me. It took me a couple hours to finish export to excel functionality when I
strugeled in .NET for 4 days and still couldn't get it to work flawlesly.
I really doubt it makes any sense to use Excel in .NET, because you're
spending more time writing code to quit excel gracefully than actually
writing business rules code which really matters. I will be making a few
more posts about other Excel and ASP.NET options . I would appreciate any
further comments.

Thank you

"Lee Gillie" <Le*@nospam.odp.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl... I've never had much luck getting OFFICE apps to run down cleanly and
consistently.

My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)

The time frame between 1 and 3 must be as short as possible.
Sanity check the process name if the above makes you uncomfortable.

Then once you have tried every trick you can think of to tell EXCEL to
shut down in a nice way, then you can see if/when the process has exited
with the .NET "Process" object. Give it a moment or two. If it still has
not gone away, then kill it!

To me, there seems to be too much voodoo in getting office automation to
avoid leaving orphaned processes out there.

HTH - Lee

Nov 21 '05 #12
You know, you could write a VB 6.0 component that does all this Excel stuff
and then call that from .NET. You would only have to worry about
ReleaseComObject on the component, not all the Excel objects.

There really isn't any great benefit of using Excel directly in .NET as you
are still using COM InterOp. Making an component that talks to Excel for
you still uses COM InterOp, but make the .NET to COM part a bit cleaner.
"LP" <lp@a.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Thanks Lee,
My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)


What do you mean scan process, could elaborate on this? Any code snippets
would be nice.

I did get it to work to certain point; just to open a file, add a workbook
and "save as" it. From everyone's comments on this thread and from my own
painful experience, I did figure out the pattern behind cleaning up excel.
Basically ReleaseComObject everything that excel object "touches" even if
it's not obvious. For example my code never directly referenced worksheets
collection, but I did referenced workbooks, but I still had to get
reference
to worksheets and ReleaseComObject it to kill excel process. I guess
underneath the covers workbooks object creates worksheets reference.

So I got that part to work, but when I started actually writing data to
excel, I quickly realized it's not going to be worth my time. Because I
literally had to Release every cell I referenced. And even then I could
miss
something not so obvious.

So I decided to do all excel related work in classic asp. I wasn't too
happy
about going back to old scripting world, but it worked out beautifully for
me. It took me a couple hours to finish export to excel functionality when
I
strugeled in .NET for 4 days and still couldn't get it to work flawlesly.
I really doubt it makes any sense to use Excel in .NET, because you're
spending more time writing code to quit excel gracefully than actually
writing business rules code which really matters. I will be making a few
more posts about other Excel and ASP.NET options . I would appreciate any
further comments.

Thank you

"Lee Gillie" <Le*@nospam.odp.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
I've never had much luck getting OFFICE apps to run down cleanly and
consistently.

My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)

The time frame between 1 and 3 must be as short as possible.
Sanity check the process name if the above makes you uncomfortable.

Then once you have tried every trick you can think of to tell EXCEL to
shut down in a nice way, then you can see if/when the process has exited
with the .NET "Process" object. Give it a moment or two. If it still has
not gone away, then kill it!

To me, there seems to be too much voodoo in getting office automation to
avoid leaving orphaned processes out there.

HTH - Lee


Nov 21 '05 #13
LP
Yes, I tired that, but I got a permision error, I didn't have time to deal
with that. That's a topic for another post anyway.
"Scott M." <s-***@nospam.nospam> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
You know, you could write a VB 6.0 component that does all this Excel stuff and then call that from .NET. You would only have to worry about
ReleaseComObject on the component, not all the Excel objects.

There really isn't any great benefit of using Excel directly in .NET as you are still using COM InterOp. Making an component that talks to Excel for
you still uses COM InterOp, but make the .NET to COM part a bit cleaner.
"LP" <lp@a.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Thanks Lee,
My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)


What do you mean scan process, could elaborate on this? Any code snippets would be nice.

I did get it to work to certain point; just to open a file, add a workbook and "save as" it. From everyone's comments on this thread and from my own painful experience, I did figure out the pattern behind cleaning up excel. Basically ReleaseComObject everything that excel object "touches" even if it's not obvious. For example my code never directly referenced worksheets collection, but I did referenced workbooks, but I still had to get
reference
to worksheets and ReleaseComObject it to kill excel process. I guess
underneath the covers workbooks object creates worksheets reference.

So I got that part to work, but when I started actually writing data to
excel, I quickly realized it's not going to be worth my time. Because I
literally had to Release every cell I referenced. And even then I could
miss
something not so obvious.

So I decided to do all excel related work in classic asp. I wasn't too
happy
about going back to old scripting world, but it worked out beautifully for me. It took me a couple hours to finish export to excel functionality when I
strugeled in .NET for 4 days and still couldn't get it to work flawlesly. I really doubt it makes any sense to use Excel in .NET, because you're
spending more time writing code to quit excel gracefully than actually
writing business rules code which really matters. I will be making a few
more posts about other Excel and ASP.NET options . I would appreciate any further comments.

Thank you

"Lee Gillie" <Le*@nospam.odp.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
I've never had much luck getting OFFICE apps to run down cleanly and
consistently.

My approach is to
1) scan processes prior to CreateObject.
(accumulate PID integer in an ArrayList)
2) CreateObject
3) scan processes again, see what is new
(verify PID integer using ArrayList.Contains)

The time frame between 1 and 3 must be as short as possible.
Sanity check the process name if the above makes you uncomfortable.

Then once you have tried every trick you can think of to tell EXCEL to
shut down in a nice way, then you can see if/when the process has exited with the .NET "Process" object. Give it a moment or two. If it still has not gone away, then kill it!

To me, there seems to be too much voodoo in getting office automation to avoid leaving orphaned processes out there.

HTH - Lee



Nov 21 '05 #14
TEH
I noticed that all of the responces are in VB!

I just tried this in C#

I seemed to have much better Luck!

TEH

"LP" wrote:
Hello,

I am trying to use .NET with Excel. I installed Office 2003 and selected
..NET programming suport option, so it installed all those PIA, as MS
sugests. But I can not find a way to destroy Excel process, it still hangs
in the taks manager' Processes as running. I am trying very simple code
(see below), but Excel wont go away, I tried just about anything I could
find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But
NOTHING works, Any help will be appreciated.
'API declaration:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
Long) As Long

' actual VB.NET Code:

Public Const WM_DESTROY = &H2

Public Const WM_USER = &H400

Dim exApplication As New Excel.Application

exApplication.DisplayAlerts = False

exApplication.Caption = "Microsoft Excel (to close)"

Dim wrk As Excel.Workbook

wrk = exApplication.Workbooks.Add()

Dim settings As New SiteSettings

Dim dir As String = settings.getAppSettingValue("TempDirectory")

Dim fileName As String = dir & Session.SessionID & ".xls"

wrk.SaveAs(fileName)

wrk.Close()

NAR(wrk)

wrk = Nothing

exApplication.Quit()

NAR(exApplication)

exApplication = Nothing

' Kill process

Dim hwnd As Long

Dim lngResult As Long

hwnd = FindWindow("XLMAIN", "Microsoft Excel (to close)")

If hwnd <> 0 Then

lngResult = SendMessage(hwnd, WM_USER + 18, 0, 0)

lngResult = SendMessage(hwnd, WM_DESTROY, 0, 0)

End If

Private Sub NAR(ByRef o As Object)

Dim i As Integer = -2

Try

While (i <> 0 And i <> -1)

i = System.Runtime.InteropServices.Marshal.ReleaseComO bject(o)

End While

Catch

Finally

o = Nothing

End Try

End Sub

Nov 21 '05 #15
I was just about to do a post on this subject having gotten absolutely
nothing on an unmonitored forum. Thanks to all who have posted before. Let's
see if my clout as an MSDN subscriber gets the promised response from MS in
24 hours:-)

MS is pushing the Office / .net interface. This cleanup is absolutely
something that has to work in a straight forward manner for their success in
this regard.

What is the secret of cleaning up Excel after having declared only the
application and a workbook? I.E. Those are the only explicit excel objects in
my project where I'm observing the problem. They are declared early. Here is
a very rough outline

dim xl as new microsoft....excel.application
dim wb as new microsoft....excel.workbook
rem do some stuff with the worksheets collection of the workbook (like read
it into the porogram)

Rem now what??????
rem hmmm ...
wk = nothing
xl.quit
xl = nothing
NAR(WK)
NAR(XL)
' now GC to beat the band
.....

I have not tried what is outlined above and won't because of the experiences
you fine folk have had. MS how about some help here.

Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices @3bears.biz

Nov 21 '05 #16
Be very careful with implicit object creation such us WorkBooks in the code

oBook = oExcel.Workbooks.Add()

See:

Office application does not quit after automation from Visual Studio .NET
client
http://support.microsoft.com/default...b;en-us;317109

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Al Christoph" <Al*********@discussions.microsoft.com> escribió en el
mensaje news:74**********************************@microsof t.com...
I was just about to do a post on this subject having gotten absolutely
nothing on an unmonitored forum. Thanks to all who have posted before.
Let's
see if my clout as an MSDN subscriber gets the promised response from MS
in
24 hours:-)

MS is pushing the Office / .net interface. This cleanup is absolutely
something that has to work in a straight forward manner for their success
in
this regard.

What is the secret of cleaning up Excel after having declared only the
application and a workbook? I.E. Those are the only explicit excel objects
in
my project where I'm observing the problem. They are declared early. Here
is
a very rough outline

dim xl as new microsoft....excel.application
dim wb as new microsoft....excel.workbook
rem do some stuff with the worksheets collection of the workbook (like
read
it into the porogram)

Rem now what??????
rem hmmm ...
wk = nothing
xl.quit
xl = nothing
NAR(WK)
NAR(XL)
' now GC to beat the band
....

I have not tried what is outlined above and won't because of the
experiences
you fine folk have had. MS how about some help here.

Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices @3bears.biz

Nov 21 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13373
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to...
3
9951
by: Vagabond Software | last post by:
Scenario: The end-user selects File-Save from my applications (WinForm) menu, specifies a filename, and waits waits for my app to write the contents of a dataset to an Excel workbook. The SaveXLReport method completes successfully, calls myXLClass.Dispose, and returns control to the user form at a base state. At this point, there is still an...
3
4502
by: Stephen Brooker | last post by:
Hi all, Just playing around a MS how-to sample to work with an Excel file from within C#. Everything is fine and I understand it OK, however when Excel and the application are closed, there is still an Excel process showing up in the task manager. Every time the app is run, another process shows up for Excel and always stays there. The only...
0
1010
by: nikedog | last post by:
I realize that xl won't scale; this is only to import legacy data into sql server. My problem is that Excel stays resident in memory after the following code. I've tried many combinations but everything leaves Excel (running under the ASPNET user) as a process running Any advice suggestions, please.
0
1121
by: tsansoterra | last post by:
I have an asp.net/vb.net app that opens Excel, creates a report and then saves the file for download. The problem I am having is the Excel process persists (visible under the Task Manager) after the quitting and setting the Excel object (and all others) = nothing. I perform this same function in classic ASP without incident. I found several...
10
3049
by: Lars-Erik Aabech | last post by:
Hi! This issue have been discussed a lot, but I haven't found a solution that applies to ASP.NET. I have a library which does some operations on Excel documents, and it will be used in an ASP.NET application. If I use the library in a Forms application, the Excel process is removed when the cleanup operations are done, but with ASP.NET all...
8
1937
by: vvenk | last post by:
Hello: I just wrote my first ASP.Net application. It worked fine on my machine and when I put into production, the ASP.Net process reaches 50% quite fast and then the system does not work anymore until I kill that process. Obviously, this is not acceptable. Looking back, I do not destroy any objects in my form. Would that be the reasn...
18
3066
by: lgbjr | last post by:
Hi All, I have a VB.NET app that, among other things, writes data to Excel. I am having trouble getting the Excel process to terminate after I quit Excel. I found an article related to this problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;317109 Below is a sample of code that I wrote based on the above article. The excel...
2
2509
by: ChrisFrohlich | last post by:
I have been trying to use the Office PIA's to write an ASP.NEt page to: 1. Open a template workbook 2. Populate some data 3. Save the file back to the server 4. Quit Excel and free up Memory I have been able to do all of the above steps except #4. Each time Excel.exe persists in memory. I have already referred to Q317109 "Office...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.