PDA

View Full Version : how to close excel file and application



kavkazi
10-13-2010, 08:55 AM
Hello,

I have an excel file which if opened at 19:00, it automatically runs a macro. When it's done, I would like to close the workbook and the excel application.

The problem is, it closes the workbook, but the excel applications stays open. I know this is tricky in VBA, and I can't figure out a way to do this.

Here is my code:



Private Sub Workbook_Open()
If Hour(Now) = 19 Then
process
Me.Close True
Application.Quit
End If
End Sub


Thanks in advance!

GTO
10-13-2010, 09:01 AM
Hi there,

You are closing the workbook first, which doesn't allow the last command to be carried out. Maybe:


Option Explicit

Private Sub Workbook_Open()
If Hour(Now) = 19 Then
Call process
If Not Me.Saved Then Me.Save
Application.Quit
End If
End Sub

Hope that helps,

Mark

kavkazi
10-13-2010, 09:07 AM
That worked!
Thanks so much