By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,267 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,267 IT Pros & Developers. It's quick & easy.

How to close EXCEL automation Server in VB?

P: n/a
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You are closing your workbook but you are not quitting Excel. Add:
ExcelServer.Quit
"Wenke Ji" <a1****@motolora.com> wrote in message
news:04****************************@phx.gbl...
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke

Nov 20 '05 #2

P: n/a
Don't use the "CreateObject" command. Use the Excel Automation model
instead, and then call .Quit() on the Excel instance when you're done.

http://support.microsoft.com/default...NoWebContent=1
"Wenke Ji" <a1****@motolora.com> wrote in message
news:04****************************@phx.gbl...
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke

Nov 20 '05 #3

P: n/a
Hi,

Use this around your .quit code:
Marshal.ReleaseComObject(objws)

objxl.Quit()

Marshal.ReleaseComObject(objxl)

HTH,

Bernie Yaeger

"Wenke Ji" <a1****@motolora.com> wrote in message
news:04****************************@phx.gbl...
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke

Nov 20 '05 #4

P: n/a
I have the same problem.
I have tried lots of things and just couldn't get it to quit.
I think one of my references may not be the correct style and is forcing
Excel to stay open but for the life of me I can't see it.

Anyone want to try?

Public Sub Export2Excel(ByVal dt As DataTable, ByVal strPath As String,
ByRef pb As ProgressBar, ByVal MyOption As String)

'add reference to Microsoft Excel

Dim objXL As Excel.Application

Dim objWBS As Excel.Workbooks

Dim objWB As Excel.Workbook

Dim objWS As Excel.Worksheet

'get a running instance of Excel - this minimizes the number of instances of
Excel in memory!

objXL = CType(GetObject(, "Excel.Application"), Excel.Application)
'create a new instance of Excel if there isn't one running.

'objXL = New Excel.Application

objWBS = objXL.Workbooks

objWB = objWBS.Add

objWS = CType(objWB.Worksheets(1), Excel.Worksheet)

'do stuff here

objWB.Close()

'problem - Excel is staying in Memory even after the Quit. It goes
away when the form is closed.

'Limited to 1 instance stuck in memory instead of unlimited number.

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWS)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWB)

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWBS)

objXL.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(objXL)

'this does not work to clear out the Excel instance from memory. Even though
it looks like "just the thing".

'http://www.dotnetinterop.com/faq/?q=OfficeCleanup

'http://support.microsoft.com/default.aspx?scid=kb;en-us;317109

'release other objects too! Still does not work. May be the remote call
issue.

objWS = Nothing

objWB = Nothing

objWBS = Nothing

objXL = Nothing

'this does not work to clear out the Excel instance from memory either.

GC.Collect()

GC.WaitForPendingFinalizers()

End Sub

--
Joe Fallon

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Hi,

Use this around your .quit code:
Marshal.ReleaseComObject(objws)

objxl.Quit()

Marshal.ReleaseComObject(objxl)

HTH,

Bernie Yaeger

"Wenke Ji" <a1****@motolora.com> wrote in message
news:04****************************@phx.gbl...
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke


Nov 20 '05 #5

P: n/a
Won't this work?

Marshal.ReleaseComObject(ExcelServer)




"Wenke Ji" <a1****@motolora.com> wrote in message
news:04****************************@phx.gbl...
Hi
I open a Excel workbook using below API:
Set ExcelServer = CreateObject("EXCEL.Application")
Set TargetWorkbook = ExcelServer.Workbooks.Open
(CurrentBook)

Befor the programm exit , I use the below API:
TargetWorkbook.Save
TargetWorkbook.Close

But I check the "Task Management" , the Excel is still at
list.
How can I close the EXCEL automation server completely in
VB program?
Thanks!

BRs
Wenke

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.