Subscriber only lesson.
Sign up to this course to view this lesson.
About this lesson
Examining the different code containers and where you should place your code.
Download this lesson’s exercise file.Where do I put my code?.xlsm
Where do I put my code?
Where you store your VBA code.
When to use
To choose the appropriate place to store your code, and find code you or someone else has written
VBA code may be stored in a variety of areas within the Visual Basic Editor, including:
- Microsoft Excel Objects
- Class Modules
- (Standard) Modules
The first 3 are quite advanced and are outside the scope of this course. For now, always store your code in a (standard) Module.
Hints & tips
- Do not store the code you write into the This Workbook or Sheet objects unless you are told to do so for a very specific reason.
- The code you write is stored in the Modules section, and you can create as many Modules as you like in the application.
- When you record a macro in Excel, the code is automatically stored in a new Module.
- If you go into an object or module and do not see “Option Explicit” at the top of the coding pane, go to Tools --> Options --> Editor and check the box for Require Variable Declaration
Lesson notes are only available for subscribers.