Having trouble closing Excel from macro...need help.


Posted by Ed Cupstid on January 19, 2002 2:27 PM

I have a batch file that starts up an Excel workbook and automatically runs a macro using auto_open, after the macro finishes it's task and saves the workbook I need the workbook to close and Excel to shutdown. Everything is working great, the workbook is saved and closes, but I can not get Excel window to close and shutdown. I am using the following code to close Excel, but it doesn't work, any help would be appreciated:

ActiveWorkbook.RunAutoMacros Which:=xlAutoClose

Dim Wb As Workbook

For Each Wb In Workbooks
If Wb.Name <> ThisWorkbook.Name Then
Wb.Close savechanges:=True
End If
Next Wb
Auto_Close

End Sub

Sub Auto_Close()
ThisWorkbook.Close savechanges:=True
End Sub

Posted by Tom Urtis on January 19, 2002 3:00 PM

As the last line in your code, you could insert

Application.Quit

which closes Excel completely.

T.U.

Dim Wb As Workbook If Wb.Name <> ThisWorkbook.Name Then Wb.Close savechanges:=True End If Next Wb Auto_Close



Posted by Ed Cupstid on January 19, 2002 3:14 PM

THANKS!!!!

That works.....I am new at this, but with the help of this board I am learning...