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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS-Excel will not close.

Status
Not open for further replies.

johnny2bad

Programmer
Nov 6, 2001
18
US
I am exporting a VSFlexGrid to a temp.xls file, then opening it in VB6, formating the workbook as needed. Then I am doing a saveas to save the excel file in the user's desired location. Everything works fine, until i run the process again. It seems that an instance of EXCEL.EXE is still running in memory. You can end it in the task manager and all is well again. But the next time you run the process the same thing happens.

I have found numerous posts about this same issue yet none have provided a solution. If i run the following code and remark out all of the workbook formating (the whole reason for this proccess) then everything runs perfectly and all processes close. but as soon as you change one cell in the workbook, excel will not close. Any ideas?

Dim XLApp As Excel.Application
Set XLApp = CreateObject("Excel.Application")

Set XLBook = XLApp.Workbooks.Open(InstallPath & "temp\temp.xls")

XLApp.Application.Visible = False
XLApp.Application.DisplayAlerts = False

'------------------------------
'Format cells/columns/rows of Workbook
'------------------------------

XLBook.SaveAs FileName:=FilePathName _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

XLBook.Close True
XLApp.Application.Quit
Set XLBook = Nothing
Set XLApp = Nothing

Thanks in advance!

John
 
You have only closed one of your workbooks - I believe saveas opens a new workbook in the new name.
Try this:

Dim wb as Excel.Workbook
For Each wb In Workbooks
wb.Close savechanges:=True
Next wb

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top