In Excel, VBA code can be stored in three different locations: in a Visual Basic module, in a Visual Basic class module, and "behind" worksheets and workbooks.
To edit code "behind" a worksheet or a workbook:
- Activate the Visual Basic Editor (press ALT+F11).
- In the Project Explorer window, you will see entries similar to the following:
VBAProject (Book1)
Microsoft Excel Objects
Sheet1 (Sheet1)
Sheet2 (Sheet2)
Sheet3 (Sheet3)
ThisWorkbook
Modules
Module1
If you double-click one of the worksheet names or
ThisWorkbook, you can type code in the code window. Such code not contained within a Visual Basic module is considered to be "behind" the worksheet or
ThisWorkbook .
If an
Auto_Open,
Auto_Close, or other
automatically-running subroutine is stored "behind" a worksheet or
ThisWorkbook, it may not function correctly when you open or close your workbook, or when you perform an action that should cause the subroutine to run.