Share via


Running Code Automatically when an Excel Add-in Is Loaded or Unloaded

To run code automatically when a Microsoft® Excel add-in is loaded, you have two choices:

  • Create a Sub procedure named Auto_Open in a standard module in the Add-In project. Any code within this procedure runs when the add-in is loaded. To run code when an add-in is unloaded, add a procedure named Auto_Close.

    –or–

  • Add code to the add-in workbook's Open event procedure. The code in this procedure also runs when an add-in is loaded, and it runs before the Auto_Open procedure runs.

Keep in mind that if you want an add-in to load automatically when Excel starts up, you must save it in the ...\Microsoft\Excel\XLStart subfolder. If the add-in is not saved in this folder, it is not loaded when Excel starts.

See Also

Excel Add-ins | Creating an Excel Add-in | Loading an Excel Add-in