how to close app in code?

G

Guest

I know this should be very simple. BUT I just could not get it work, and I
did not find any documentation on how to close an excel app from MSDN.

I created the app in vb6 as,
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")
and after populated the sheet,
xlWb.Saveas ("C:\northwind\mynwtbl.xls")
' xlWb.Close
With above line the only the workbook closed, but not excel itself.
' xlApp.Windows("C:\northwind\mynwtbl.xls").Close
With above line I got "subscript out of range" error.
'Set xlApp = Nothing
No working either.

Thanks!
 
T

Tom Ogilvy

Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")
and after populated the sheet,
xlWb.Saveas ("C:\northwind\mynwtbl.xls")
xlWb.Close
set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
 
G

Guest

Thanks Bob and Tom!

Tom Ogilvy said:
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")
and after populated the sheet,
xlWb.Saveas ("C:\northwind\mynwtbl.xls")
xlWb.Close
set xlWb = Nothing
xlApp.Quit
Set xlApp = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top