How to close EXCEL automation Server in VB?  
Author Message
Dad23G





PostPosted: Sun Oct 19 22:05:48 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB?

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

Visual Studio33  
 
 
Scott





PostPosted: Sun Oct 19 22:05:48 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB? You are closing your workbook but you are not quitting Excel. Add:
ExcelServer.Quit




> 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


 
 
Robert





PostPosted: Sun Oct 19 23:49:12 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB? 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.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q301/9/82.ASP&NoWebContent=1




> 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


 
 
Bernie





PostPosted: Mon Oct 20 09:04:25 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB? Hi,

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

objxl.Quit()

Marshal.ReleaseComObject(objxl)

HTH,

Bernie Yaeger



> 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


 
 
Joe





PostPosted: Mon Oct 20 22:52:29 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB? 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.ReleaseComObject(objWS)

System.Runtime.InteropServices.Marshal.ReleaseComObject(objWB)

System.Runtime.InteropServices.Marshal.ReleaseComObject(objWBS)

objXL.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(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





> Hi,
>
> Use this around your .quit code:
> Marshal.ReleaseComObject(objws)
>
> objxl.Quit()
>
> Marshal.ReleaseComObject(objxl)
>
> HTH,
>
> Bernie Yaeger
>


> > 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
>
>


 
 
Robin





PostPosted: Thu Oct 23 08:43:10 CDT 2003 Top

Visual Basic [VB] >> How to close EXCEL automation Server in VB? Won't this work?

Marshal.ReleaseComObject(ExcelServer)












> 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