Link to home
Create AccountLog in
Avatar of jcampanali

asked on

Close Excel Workbook and App with VBA

I have a Windows 7 scheduled task that opens a 2003 version .xls workbook(Office 2007) which fires off VBA process with On_Open event. I have code that closes workbook and shuts down app, however it cannot shut itself down within same workbook. So, I wrote a batch file to kill excel process 15 minutes after task runs (taskkill /im excel.exe /f ). However, I keep getting the Document Recovery screen when I try to manually open workbook. How can I either:

Shut Down workbook/app with VBA code in same .xls file or
Suppress Document Recovery panel from appearing when running batch script(I've tried checking box Disable AutoRecover for this workbook only - and that has no effect.

Many thanks....
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Does the VBA in the workbook include something like:

ThisWorkbook.Close SaveChanges:=False

Avatar of CRJ2000
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jcampanali


This is the code I have at the end of routine...
    ActiveWorkbook.Close True

Should I nix the ActiveWorkbook.Close True line?
I would change the True to False since you have already saved it.
Also, if that code is in the workbook you are saving, use ThisWorkbook rather than ActiveWorkbook.
Yes, you can safely eliminate the ActiveWorkbook.Close, since quitting Excel automatically closes all workbooks.