Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an Excel 2000 Workbook Using VB6

Status
Not open for further replies.

chamira

Programmer
Apr 17, 2001
6
US
I'm trying to manipulate Excel 2000 workbooks using little executables I'm creating in VB6. I can open, manipulate and save the spreadsheets with out any problems, but I cannot seem to close Excel, even after I've written the code to close out of Excel. I know this because when I press Ctl+Alt+Del after running my program, there is an instance of Excel running.

The code below is the code I've used to open and close an Excel workbook. If anyone else has had this problem and can help me out it would be much appreciated.

Dim xlApp As Excel.Application
Dim wrkBook As Excel.Workbook
Dim wrkSheet As Excel.Worksheet

Set xlApp = CreateObject("Excel.Application")
Set wrkBook = xlApp.Workbooks.Open("C:\anyFile.xls")

...

wrkBook.Close
xlApp.Quit
Set wrkSheet = Nothing
Set wrkBook = Nothing
Set xlApp = Nothing

P.S. The funny thing is, if I try to create a new workbook instead of opening one, i.e. using
Set wrkBook = xlApp.Workbooks.Add
it works fine, and Excel closes at the end.
 
hia

mabye this is an answer to your problem

try to unload excel before you close excel...

wrkBook.Unload
xlApp.Unload

i hope its going to work

if not tell me
and mabye i have another anwser

Grtz
chris govaarts
:)
 
Thanks for your help! I tried it again, and the reason it wasn´t working before was that I had the code for closing the connection in a different procedure, which for some reason wasn´t being called.

I had them in the Form_Unload procedure, but for some reason, it doesn´t run when I click on the close button in the control box. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top