Closing Excel files from VB (1 Viewer)

Elvis

Registered User.
Local time
Today, 06:47
Joined
Sep 28, 2001
Messages
26
I have an excel file that I want to update a cells data then save the file anc exit out of the excel application. It seems to work ok except when it comes to closing the excel application. It seems to keep the excel file locked this is the code I have to open/close the file

Dim app As New Excel.Application

app.Workbooks.Open "test.xls"

app.Range("A1").Select

ActiveCell.Offset(0, 0).Value = Date

ActiveWorkbook.Save
app.Workbooks.Close
app.Quit

Anyone know what I am doing wrong.
 

Opengrave

Registered User.
Local time
Today, 00:47
Joined
Sep 6, 2001
Messages
70
Just guessing but try to specify the file to close.

app.Workbooks.Close "test.xls"
 

Elvis

Registered User.
Local time
Today, 06:47
Joined
Sep 28, 2001
Messages
26
Tried That, although in slightly different syntax.

app.workbooks("name.xls").close

The file excel file I have open does close eventually. Having a closer look at the system I seem to have multiple instances of EXCEL.EXE running though. If I have run this a few times. Just does not seem to shutdown the running application.

Thanks for your response
 

Users who are viewing this thread

Top Bottom