Auto_Close Procedures

An Auto_Close procedure runs just before the workbook containing the procedure closes. You can use this feature to restore menu bars, toolbars, and other elements of the user interface to their previous condition and to save and close the files that support an application.

You can also use an Auto_Close procedure to ensure an orderly disconnection from another application. For example, if your application uses Windows Terminal to download stock quotations from a remote information service, you probably want Terminal to log off from the service before you close the workbook, as shown in the following procedure.


Sub Auto_Close()
    MenuBars(xlWorksheet).Menus("Tools"). _
        MenuItems("My Analysis").Delete
    CloseLogFile            'Procedure: close transaction file.
    DisconnectService    'Procedure: disconnect info service.
End Sub