MrExcel Publishing
Your One Stop for Excel Tips & Solutions

How to close a file when closing excel

Posted by Greg G on October 31, 2001 8:41 AM

I am looking for the code that will do the following:

If I have 4 spreadsheets open, A.xls, B.xls, C.xls, D.xls

When C.xls is closed, I would also like to close A.xls.

Thanks in advance for your help.


Posted by Tom Urtis on October 31, 2001 9:36 AM

Place this code in your Auto_Close or Worbook Close event of your Workbook C. It has an error trap in case Workbook A is not open when you close C. It also auto saves both files in the process. If you don't want the auto save, delete those 2 lines and begin the code with
Application.DisplayAlerts = False
and end the code with
Application.DisplayAlerts = True

On Error Resume Next

Tom Urtis